posted 17 years ago
Bhaskar

You can think of floor and ceil as rounding the arguments. For floor it rounds the argument down (towards negative infinity) to the next whole integer, so these two lines

System.out.println(Math.floor(1.2));

System.out.println(Math.floor(-1.2));

will print

1

-2

Math.ceil rounds the argument up (towards positive infinity), so the lines

System.out.println(Math.ceil(1.2));

System.out.println(Math.ceil(-1.2));

will print

2

-1

It's fairly obvious how to do the positive numbers but the negative numbers are what throw me sometimes. There are some special cases for when the number is NaN or when it is one of the infinities, check out the API for the exact details.

hope this helps

Dave

[This message has been edited by Dave Vick (edited July 05, 2001).]