I came up with a problem while using Math.ceil() method. Shouldn't it give the closest integer bigger than the parameter if we typecast the result to integer? For the specific value (int)Math.ceil(1/5) gives 0 as a result. How should I use it to get 1 instead?
Asked
Active
Viewed 468 times
1 Answers
0
1/5 using integer math produces 0. You need to use floating point math to get 0.2 so that ceil
has something to round up.
(int) Math.ceil(1.0/5.0)

John Kugelman
- 349,597
- 67
- 533
- 578