The actual solution is to use double inside the ceil method.
Math.ceil(7 * 50 / 100) will return 3.0 , although the actual value obtained as a result of 7*50/100 Math.ceil(7 * 50 / 100) is 3.5 . This is because, since everything is int , the result of 350/100 itself will be 3 .
If, however, if you give Math.ceil(7 * 50 / 100D) , the result will be 4.0 .
So, 4.999 in your question should be double , and not the result of an integer operation like 4999/1000 .
Just make sure that everything you give inside ceil is double , not int .
source share