0

Possible Duplicate:
Floating point inaccuracy examples

In the first, I apologize for my poor English.

We all know Java float number calculation error. Such as follows:

System.out.println(0.0934 * 1000);
System.out.println(0.0935 * 1000);
System.out.println(0.0936 * 1000);

The result is

93.39999999999999
93.5
93.60000000000001

And we can use BigDecimal to resolve this problem.

I want to know the principle of the error. What reason caused the problem.

Thanks.

Community
  • 1
  • 1
rainisic
  • 65
  • 1
  • 7
  • 4
    http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html – Mysticial Oct 12 '12 at 02:11
  • 2
    Also: http://floating-point-gui.de/ – leonbloy Oct 12 '12 at 02:13
  • Tons of similar questions: http://stackoverflow.com/questions/9461744/explain-this-floating-point-behavior http://stackoverflow.com/questions/2100490/floating-point-inaccuracy-examples http://stackoverflow.com/questions/7581741/floating-point-error-in-representation – leonbloy Oct 12 '12 at 02:14
  • Mysticial, Greg Hewgill, leonbloy. Thanks a lot. – rainisic Oct 12 '12 at 02:25

0 Answers0