I have a number ("double") from int/int (such as 10/3).
What's the best way to Approximation by Excess and convert it to int on C#?
That is, the answer is always rounding down.
Since double is bigger data type than int, you can simply downcast double to int in Java. double is 64-bit primitive value and when you cast it to a 32-bit integer, anything after the decimal point is lost.
As we know double value can contain decimal digits (digits after decimal point), so when we convert double value with decimal digits to int value, the decimal digits are truncated.
Are you asking about System.Math.Ceiling?
Math.Ceiling(0.2) == 1 Math.Ceiling(0.8) == 1 Math.Ceiling(2.6) == 3 Math.Ceiling(-1.4) == -1
int scaled = (int)Math.Ceiling( (double) 10 / 3 ) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With