Read <a href="http:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;cs257&#x2F;archive&#x2F;florian-loitsch&#x2F;printf.pdf" rel="nofollow">http:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;cs257&#x2F;archive&#x2F;florian-loitsch&#x2F;pr...</a> and, if you still need more info, a few of the earlier papers it references.<p>All of them may be correct as typically, multiple &#x27;answers&#x27; can be correct. One could argue that given a number, one should print the shortest string that round-trips to that number, but that may mean that one prints &quot;0.3&quot; while the &#x27;real&#x27; value is closer to 0.30000000000000004 or 0.29999999999999998 (a representation that one of the algorithms in the above paper gives) or possibly even equal to it.<p>Also, some of them may be incorrect for backwards compatibility reasons. In the eyes of some, that makes them correct again.<p>And don&#x27;t get round to not doing it yourself :-)