using struct pack and unpack on floating point number 0.01 output 0.009999999776482582.
<p>using 'struct pack and unpack' on floating point number 0.01 outputs 0.009999999776482582. 
For my project I would have to configure values which are float
and the same needs to be stored in binary file and I would need this data to analyze later and I need the exact values that was configured. </p>

<p>Can some one help me if there is any way that I could store the exact value 0.01 and retrieve the same.</p>

<p>Based on some of the post I have already tried using double instead of float and it works but the problem with using double is my file size increases. I have a lot of parameters which is float and can take values any where between 0 to 5. 
Hence any other suggestion would be appreciated. </p>

<p>Here is the sample code</p>

<pre><code>import struct
a = 0.01
b = struct.pack('&lt;f', a)
c = struct.unpack('&lt;f', b)
print c
(0.009999999776482582,)
</code></pre>

<p>There is no floating point number <code>0.01</code>. IEEE floating point numbers do not represent the entire real number line; they represent an approximation using a particular binary scheme. The closest approximation has the decimal representation 0.009999999776482582. </p>

<p>You could try serializing a textual representation (e.g. json) or pickle a BigDecimal which can represent arbitrary precisions.</p>

python