precision of float in a dict

Alex Martelli aleaxit at yahoo.com
Fri May 23 09:14:14 EDT 2003


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