Dict handling of floats

Mel Wilson mwilson at the-wire.com
Thu Apr 24 23:33:18 EDT 2003


In article <98imn-ust.ln1 at grendel.myth>,
Jim Richardson <warlock at eskimo.com> wrote:
>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? I am not doing anything special as
>far as I can tell, just stuffing the numbers into a dict, and recalling
>it later. This is with Python 2.2 on Linux, and no, it's not an original
>Pentium :)

   Chances are that the float hasn't changed, but that
you're printing it in a different way.  You'll see this kind
of difference between `repr(float_value)` and
`str(float_value)` and `"%f"%(float_value,)" and
`"%g"%(float_value,)`.

        Regards.        Mel.




More information about the Python-list mailing list