public static int round(float a)
Returns the closest int to the argument. The result is rounded to an integer by adding 0.5, taking the floor of the result, and casting the result to type int.
Eg1: Math.round(35.6)
Step 1: add 0.5 i.e. 35.6 + 0.5 = 36.1
Step 2: find the floor ( i.e. value towards �ve infinity i.e. greatest integer less than
or equal to given value)
for 36.1 greatest integer, which is less than or equal to 36
hence Math.round(35.6) = 36
Eg2: Math.round(-37.8)
Step 1: add 0.5 i.e. �37.8 + 0.5 = -37.3
Step 2: find the floor ( i.e. value towards �ve infinity i.e. greatest integer less than
or equal to given value)
for -37.3 greatest integer, which is less than or equal to �38
( -37.3 > -38 , -37.3 < -37)
hence Math.round(-37.3) = -38
Math.round() adds .5 to the argument then performs a floor(). Since the code adds an additional .5 before round() is called, it�s as if we are adding 1 then doing a floor().
Math.round(values[x] + .5) means Math. floor ( values[x]+0.5+0.5) i.e. Math.floor(values[x]+1)
Given values are {-2.3, -1.0, 0.25, 4}; to find Math.round(values[x] + .5)value add +1 and apply floor.
Regards
Naresh
[ December 21, 2005: Message edited by: Naresh Kumar ]