How do I convert a decimal to an int in C#?

Neil P picture Neil P · Feb 1, 2009 · Viewed 331.9k times · Source

How do I convert a decimal to an int?

Answer

jason picture jason · Feb 1, 2009

Use Convert.ToInt32 from mscorlib as in

decimal value = 3.14m;
int n = Convert.ToInt32(value);

See MSDN. You can also use Decimal.ToInt32. Again, see MSDN. Finally, you can do a direct cast as in

decimal value = 3.14m;
int n = (int) value;

which uses the explicit cast operator. See MSDN.