Who told str() to round my int()'s!!!

Zentrader zentraders at gmail.com
Sat Aug 11 15:37:36 EDT 2007


On Aug 11, 9:40 am, "Adam W." <AWasile... at gmail.com> wrote:
> 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?

If 15 digit precision is a concern, I would suggest that you us the
decimal class instead of floating points.  Floating point problems on
X86 machines are well documented.
http://docs.python.org/lib/module-decimal.html
http://pydoc.org/2.4.1/decimal.html
http://gmpy.sourceforge.net/




More information about the Python-list mailing list