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

Steve Holden steve at holdenweb.com
Sat Aug 11 15:39:00 EDT 2007


Roel Schroeven wrote:
> 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
> 
> 
I should also point out that the subject line for this thread is 
inaccurate, as it wasn't rounding ints at all.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list