File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Math.floor with negative numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math.floor with negative numbers" Watch "Math.floor with negative numbers" New topic

Math.floor with negative numbers

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
hi there....
what do you think the answer is?
-3.0 that's what.
i thought it rounded towards zero...i guess it does with positive numbers, but the point is that .floor gets the lowest whole number... so therefore it must be -3.0 ... silly little things like that must be watched for on the exam eh.

giddee up
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
You are correct.
Think about 'floor', which is always lower than you, regardless negative or positive.
Abbas Alafoo

Joined: Feb 06, 2003
Posts: 24
a funny thing about Math.ceil:
Math.ceil(-0.5) is -0.0 and not 0.0 !

I agree. Here's the link:
subject: Math.floor with negative numbers
It's not a secret anymore!