| Author |
Math.round( -.5)?
|
Tom Adams
Ranch Hand
Joined: Feb 07, 2003
Posts: 56
|
|
Does it seem odd that java rounds -.5 to zero? Is that right?
|
Tom
|
 |
Jessica Sant
Sheriff
Joined: Oct 17, 2001
Posts: 4313
|
|
check out the API for Math.round(double) Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression: (long)Math.floor(a + 0.5d) So... it behaves just like it's supposed to.
|
 |
Tom Adams
Ranch Hand
Joined: Feb 07, 2003
Posts: 56
|
|
|
Yea...I read that also. Is it just me or does this seem strange? Just as a check excel and MS SQL Server both feel that -.5 should be rounded to -1. :roll:
|
 |
Jessica Sant
Sheriff
Joined: Oct 17, 2001
Posts: 4313
|
|
lol yes -- it does seem a little strange... maybe you can write your own method called long roundTheWayIExpectItToBehave(double d) and use that??
|
 |
 |
|
|
subject: Math.round( -.5)?
|
|
|