This week's giveaway is in the Groovy forum. We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line! See this thread for details.

"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."

I am not sure, but this could be the way you do it. First add 0.5 to the argument and than perform a Math.floor() on it.

Here f6=-5.49 -5.49 + 0.5 = -4.99 Now, we perform a Math.floor() on -4.99 giving -5, because -5 is less than -4.

Similarly f7=5.49 5.49 + 0.5 = 5.99 Now, we perform a Math.floor() on 5.99 giving 5, because 5 is less than 6.

Math.round() returns integer closest to the argument in the case above because the arguments are of type float. [ June 17, 2005: Message edited by: Abdulla Mamuwala ]

Rounds off to the nearest integer: -5 and 5 respectively.

Given -5.5 and 5.5 you need a rounding rule since there are two "nearest" integers. They decided to round up: -5, 6 respectively. In other words if smack dab in the middle add 0.5.

shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63

posted

0

Thanxs a lot for the wonderful replies!!

Don't get me started about those stupid light bulbs.