Here's how the round() method is in the source
<pre>
public static int round(float a) {
return (int)floor(a + 0.5f);
}
</pre>
And here's what the floor method does(since it's native refer to API)
<pre>
floor
public static double floor(double a)
Returns the largest (closest to positive infinity) double
value that is not greater than the argument and is equal to a mathematical integer.
Parameters:
a - a double value.
a - an assigned value.
Returns:
the largest (closest to positive infinity) double value that is not greater than the argument and is equal
to a mathematical integer.
</pre>
So to estimate the rounded off value we add 0.5 to our number & then get the largest double value that is not greater than the argument & is equal to a maths integer . For instance
Math.round(-5.49f)
Add 0.5 ---> -5.49 + 0.5 = -4.99
Get the largest double value
that's a maths integer
but not greater than the argument ----> -5
So , Math.round(-5.49) = -5
Correct me if I'm wrong ( First time i've looked at the source)
Ashish
[This message has been edited by Ashish Hareet (edited July 29, 2001).]