0

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?

dev1ce
  • 101
  • 3
  • 11

1 Answers1

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
  • 330,190
  • 66
  • 504
  • 555