Original Post Gayatri Ganesh

I understood the answer for f5,f6 and f7 but isn't f4 = -4 ? Please explain

Math.round(-5.5f) is internally calculated as (int)Math.floor(-5.5 + 0.5 ) which is (int)Math.floor(-5.0) = -5

Hence the answer is -5

I would say, if you know how to calculate Math.floor function correctly then Math.round() should be very easy. Math.round(x) is equivalent to

(int)Math.floor(x + 0.5) if x is float.

(long)Math.floor(x + 0.5) if x is double.

Hope this helps you...

[ January 18, 2005: Message edited by: Jay Pawar ]