Does anyone know why Math.floor(-100.6) results in -101.0? I thought floor was suppose to return the largest double value that is not greater than the arguement. -100 is larger than -101. So why doesnt't it return -100. Is the method floor actually calculating on the absolute value of the value passed. Like: Math.floor(-100.6) 1. takes -100.6 and computes on 100.6. 2. 101.1 = 100.6 +.5 3. returns the long of 101.1 which is 101 4 the final result would then be -101.00
It cannot return -100, because -100 is GREATER than -100.6. So the closest value is -101. The closer a negative number is to zero, the larger it is. Hope this helps.
Charlie, It helps to physically visualize a room "ceiling" and "floor". Floor is at your feet and the ceiling is above your head. <*****> Ceil XXX <-----> Floor For positive number, it's easy. You just put your number where the XXX is and bracket it with the top and bottom non-decimal number. E.g. 10.2 <*****> Ceil = 11.0 10.2 <-----> Floor = 10.0 For negative numbers, it gets a little tricky. You just have to remember that a smaller negative number is actually larger than a big negative number. So you do the reverse. E.g. -100.6 <*****> Ceil = -100.0 -100.6 <-----> Floor = -101.0 There are a couple of special cases you'll have to memorize, but they aren't too difficult. Look at the API. -Peter