Round down

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hi,

How can I round down?

See this sample: 5 / 3 = 1.67
Now I want the answer/value 1.

Thanks!
 
Hello!
How can I round down?
See this sample: 5 / 3 = 1.67
Now I want the answer/value 1.


You can use the Math.Floor() method.

double integerResult = Math.Floor(1.67);
 
I think if you do integer calculations, that happens automatically. Or just
cast it to an integer.
 
Arjen said:
How can I round down?

See this sample: 5 / 3 = 1.67
Now I want the answer/value 1.

Integer division in C# is always rounded towards zero. If that's all
you need, just do the division with integer operands.

If you need actual rounding *down* (even when the result is negative)
you probably want Math.Floor.
 
Back
Top