title: printing float, preserving precision
body: <p>I am writing a program that prints floating point literals to be used inside another program.</p>
  
  <p>How many digits do I need to print in order to preserve the precision of the original float?</p>
  
  <p>Since a float has <code>24 * (log(2) / log(10)) = 7.2247199</code> decimal digits of precision, my initial thought was that printing 8 digits should be enough. But if I'm unlucky, those <code>0.2247199</code> get distributed to the left and to the right of the 7 significant digits, so I should probably print 9 decimal digits.</p>
  
  <p>Is my analysis correct? Is 9 decimal digits enough for all cases? Like <code>printf("%.9g", x);</code>?</p>
  
  <p>Is there a standard function that converts a float to a string with the minimum number of decimal digits required for that value, in the cases where 7 or 8 are enough, so I don't print unnecessary digits?</p>
  
  <p>Note: I cannot use hexadecimal floating point literals, because standard C++ does not support them.</p>