Dict handling of floats

Peter Hansen peter at engcorp.com
Fri Apr 25 15:09:20 CEST 2003

Raymond Hettinger wrote:
> [Jim]
> > >I have come across a weirdness. I have a number of floats, (lat long
> > >pairs) which I stuff into a dict, but when I take them out, my nice %2f4
> > >number, (say, 47.5894) is something long and *almost* right, like
> > >47.589333333333333339. What gives?
> [Mel]
> >    Chances are that the float hasn't changed, but that
> > you're printing it in a different way.
> The Python FAQ has a pretty good explanation:
> http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp

I looked for the FAQ entry to offer as well, but I wasn't satisfied
with that one.  It refers to apparent errors from numerical calculations,
not primarily to the representation of the float when printed.

Is the OP's question deserving of a separate entry in the FAQ, or
at least an addendum to the one Raymond linked above?


More information about the Python-list mailing list