Floating point is (usually) about &quot;closest representable value&quot;. That is, the normal floats form a finite subset of the real numbers, and a calculation like x + y will pick the closest element to the true result.<p>In this case, adding the closest floating point value to &quot;0.1&quot; (0x1999999999999a &#x2F; 2^56) and the closest one to &quot;0.2&quot; (0x1999999999999a &#x2F; 2^55) gives<p><pre><code>  0x13333333333334 &#x2F; 2^54
</code></pre>
which is exactly<p><pre><code>  0.3000000000000000444089209850062616169452667236328125
</code></pre>
(Rational numbers with a denominator that&#x27;s a power of two have a finite decimal representation, and that&#x27;s the full one for this number.)<p>However, when printing, one is either interested in a close-enough rounded value (e.g. like some languages print 0.3 by default, or how %.3f will explicitly limit to 3 digits), or an exact representation. The exact representation should be round-trippable, so when you read it back in, you get exactly the same value. In practice this means printing a float z as a decimal value such that the closest float to the exact decimal value (i.e. as a real number) is z. Obviously the full string above works because it is exact, but it is nice to be as short as possible. In this case, the floats immediately before and after our number are exactly<p><pre><code>  0.299999999999999988897769753748434595763683319091796875
  0.300000000000000099920072216264088638126850128173828125
</code></pre>
So, only printing up to the first 4 is enough to uniquely identify our float: it is the closest one.<p>The 0.2999* float is slightly interesting: it is the closest float to 0.3, and most environments will print &quot;0.3&quot; in exact mode.<p>There&#x27;s a lot of trickery&#x2F;research around printing[1] and operating on floats: rounding things correctly can be highly non-trivial[2].<p>[1]: e.g. <a href="http:&#x2F;&#x2F;www.cs.indiana.edu&#x2F;~dyb&#x2F;pubs&#x2F;FP-Printing-PLDI96.pdf" rel="nofollow">http:&#x2F;&#x2F;www.cs.indiana.edu&#x2F;~dyb&#x2F;pubs&#x2F;FP-Printing-PLDI96.pdf</a><p>[2]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rounding#Table-maker.27s_dilemma" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rounding#Table-maker.27s_dilem...</a>