decimal - int

  • Thread starter Thread starter Guest
  • Start date Start date
Hi Dave,

You cast it to int

decimal d = 10;
int i = (int)d;

Another method would be

int i = Convert.ToInt32(d);
 
Int32.Parse() converts a string to an int, not a decimal to an int.

Depending upon how you want to perform the conversion, you might also
want to look at Math.Ceiling and Math.Round. For example:

Decimal d = 5.56;
int i = (int)Math.Round(d);
int j = (int)d;

After this code, i will contain the value 6, while j will contain the
value 5.
 
Back
Top