Home Ask Login Register

Developers Planet

Your answer is one click away!

Razorbolt February 2016

What is the difference between round() and ceil() in java

I am wondering what may be the difference between the two methods round() and ceil() in the package Math in java and why they don't return an integer?


Safwan Ahmed February 2016

Round will convert 3.3 into 3 while ceil will convert the same into 4. Hope you understood.

Louis Wasserman February 2016

Math.round is underspecified, and I believe its behavior has actually changed in the past -- see http://bugs.java.com/view_bug.do?bug_id=6430675 -- but generally speaking it behaves like RoundingMode.HALF_UP, which has an extensive table of its differences from RoundingMode.CEILING or RoundingMode.FLOOR.

Post Status

Asked in February 2016
Viewed 2,759 times
Voted 11
Answered 2 times


Leave an answer

Quote of the day: live life