I've read a lot about float representation recently (including this: How To Represent 0.1 In Floating Point Arithmetic And Decimal).
Now I understand that 0.1 can't be represented correctly, and when I do this:
System.out.println(2.0f - 1.9f);
I'll never get precise result.
So the question is:
How represented 0.1f in the following code in order to print 0.1 correctly?
Is that some kind of syntatic sugar?
In the article that I above mentioned says: 0.1 represented in memory as 0.100000001490116119384765625. So why I don't get this output for this code:
System.out.println(0.1f);
How does Java deal with this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…