precision of float in a dict

Sven Brandt sven_NOSPAM at manastar.de
Fri May 23 10:06:39 EDT 2003


Hi Alex,

Thank you and the others for pointing me to the info.
The limited precision of a float is clear now.

I'm still curious why the value stored in a dict is different from the 
one of the float. I guess, repr() is called twice on the value in the 
dict (Not realy important, I' just trying to understand).

Regards
Sven

Alex Martelli schrieb:
> Sven Brandt wrote:
> 
> 
>>Hi,
>>
>>has a float value in a dictionary a lesser precision than 'outside'?
> 
> 
> No.  See http://www.python.org/doc/current/tut/node14.html and FAQ
> http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp --
> the repr/str distinction is what's biting you, in an obscure but alas
> often met with way (when you ask a container for its str, as in using
> it in a print, it in turn asks its item for their repr, NOT their str,
> allegedly to avoid confusing you if some items are strings which may
> include commas and other punctuation).
> 
> 
>>Since I'm doing some (small scale) accounting using Python I was just
>>wondering ...
> 
> 
> Binary floating point numbers are generally not ideal for accounting
> and other financial purposes.  You might want to look into any of the
> various decimal, fixed-point and rational number types that exist as
> add-ons to Python.
> 
> 
> Alex
> 





More information about the Python-list mailing list