title: Converting a Python Float to a String without losing precision
body: <p>I am maintaining a Python script that uses <code>xlrd</code> to retrieve values from Excel spreadsheets, and then do various things with them. Some of the cells in the spreadsheet are high-precision numbers, and they must remain as such. When retrieving the values of one of these cells, <code>xlrd</code> gives me a <code>float</code> such as 0.38288746115497402.</p>
  
  <p>However, I need to get this value into a string later on in the code. Doing either <code>str(value)</code> or <code>unicode(value)</code> will return something like "0.382887461155". The requirements say that this is not acceptable; the precision needs to be preserved. </p>
  
  <p>I've tried a couple things so far to no success. The first was using a string formatting thingy:</p>
  
  <pre><code>data = "%.40s" % (value) 
  data2 = "%.40r" % (value) 
  </code></pre>
  
  <p>But both produce the same rounded number, "0.382887461155". </p>
  
  <p>Upon searching around for people with similar problems on SO and elsewhere on the internet, a common suggestion was to use the <code>Decimal</code> class. But I can't change the way the data is given to me (unless somebody knows of a secret way to make <code>xlrd</code> return Decimals). And when I try to do this:</p>
  
  <pre><code>data = Decimal(value)
  </code></pre>
  
  <p>I get a <code>TypeError: Cannot convert float to Decimal.  First convert the float to a string.</code> But obviously I can't convert it to a string, or else I will lose the precision.</p>
  
  <p>So yeah, I'm open to any suggestions -- even really gross/hacky ones if necessary. I'm not terribly experienced with Python (more of a Java/C# guy myself) so feel free to correct me if I've got some kind of fundamental misunderstanding here.</p>
  
  <p>EDIT: Just thought I would add that I am using Python 2.6.4. I don't think there are any formal requirements stopping me from changing versions; it just has to not mess up any of the other code.</p>