aspose file tools*
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
Author

Math.floor with negative numbers

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
hi there....
System.out.println(Math.floor(-2.1));
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
Greenhorn

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


SCJP
 
Don't get me started about those stupid light bulbs.
 
subject: Math.floor with negative numbers