Rounding up doesn't work
int a = 28;
int b = (int) Math.ceil(a * 200 / 900);
sout(b)
Outputs 6. Waiting for 7.
A regular calculator gives you 28 * 200 / 900 = 6.2222, and I expect this code to round up.
What am I doing wrong?
0
1 answers
You have all operations integer, so everything is correct
28*200/900=5600/900=6
You should do this:
28*200.0/900=5600.0/900=6.2222
Math.ceil(6.2222)=7.0
3
Author: Barmaley, 2017-09-25 16:52:13