Hi All, I have tested the round function with the following values. 1)float f = 4.4999999f; System.out.println(Math.round(f)); prints-- 5 2)float f = 4.499999f; System.out.println(Math.round(f)); prints-- 4

i just want to know the how the round function is working. Why the difference in the result with some minar change. thanks in advance.

4.999999f is internally represented by the same bit pattern that represents 5.0f. Check out this code:

The output is:

4.5 is represented as 1083179008 4.4999999f is represented as 1083179008 4.499999f is represented as 1083179006

The last representation has a 6 in the ls digit.

-- Phil

Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".