title: Python Float Formatting Minimum Characters
body: <p>I am reading a large ascii file, converting to binary, and compressing it to reduce file size.  I would like to reproduce the original file exactly.  However, number formatting is an issue.  I believe the original file is printed with the minimum number of characters required to uniquely identify the floating point number.</p>
  
  <pre><code>import struct
  x = [3.14, 3.1]
  y = list(struct.unpack('2f', struct.pack('2f', *x)))
  print str(x)
  print str(y)
  </code></pre>
  
  <p>Which returns
      [3.14, 3.1]
      [3.140000104904175, 3.0999999046325684]</p>
  
  <p>I would like to print y exactly like x.  How can I do that?  Also, I don't understand what magic is taking place under the hood with the str function.  Can you please explain?  I am using Python 2.7.</p>
  
  <p>Update:</p>
  
  <pre><code>import struct
  x = [3.14, 3.1]
  y = list(struct.unpack('2d', struct.pack('2d', *x)))
  print str(x)
  print str(y)
  </code></pre>
  
  <p>The code above returns:</p>
  
  <pre><code>[3.14, 3.1]
  [3.14, 3.1]
  </code></pre>
  
  <p>So the str function truncates characters, but only when the value is very close to to the 64 bit floating point value.  I would like similiar behavior when the value is very close to the 32 bit floating point value.</p>