This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Similar Threads
how to split a number into two multipliyers
using the math class for rounding numbers
Math.round() method
What is Ceil, Floor, Float, Double