Who told str() to round my int()'s!!!
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Sat Aug 11 13:33:57 EDT 2007
Adam W. schreef:
> After a fair amount of troubleshooting of why my lists were coming
> back a handful of digits short, and the last digit rounded off, I
> determined the str() function was to blame:
>
>>>> foonum
> 0.0071299720384678782
>>>> str(foonum)
> '0.00712997203847'
>
> Why in the world does str() have any business rounding my numbers, and
> how do I get around this?
You could use repr() instead of str() (AFAIK that's what the interactive
interpreter used to print your foonum), but in any case you should be
aware of the limits inherent in floating point arithmetic and in
conversions between decimal and binary fractions. See e.g.
http://docs.python.org/tut/node16.html
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-list
mailing list