File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Math.floor with negative numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
 
 
subject: Math.floor with negative numbers
 
Threads others viewed
using the math class for rounding numbers
Math.Round
What is Ceil, Floor, Float, Double
Math.round() method
how to split a number into two multipliyers
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture