[python] struct module round off error?

Peter Hansen peter at engcorp.com
Fri Jun 11 15:08:42 CEST 2004


David Stockwell wrote:

> When I first set it and print it, it has the correct value  (50.3).
> 
> However all i did was pack it, and then unpack it and it lost its 
> definite value of 50.3.
> After the unpack it was approximately 50.3 (50.29999......)

Actually, they have the same value each time.  See
http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate
for more...

(Hint: try repr(d) right after you do d=50.3 and see what you get.)

-Peter



More information about the Python-list mailing list