precision of float in a dict

Fredrik Lundh fredrik at pythonware.com
Fri May 23 08:52:14 EDT 2003


Sven Brandt wrote:

> has a float value in a dictionary a lesser precision than 'outside'?
>
> E.g.
>
>    my_float=0.1
>    my_dict={'my_value':my_float}
>    print my_float
>    print my_dict
>    return printed
>
> returns
>
> 0.1
> {'my_value': 0.10000000000000001}

the answer is no:

>>> my_float = 0.1
>>> my_dict = {"my_value": my_float}
>>> print my_float
0.1
>>> print repr(my_float)
0.10000000000000001
>>> print my_dict
{'my_value': 0.10000000000000001}
>>> print repr(my_dict)
{'my_value': 0.10000000000000001}

> Since I'm doing some (small scale) accounting using Python I was just
> wondering ...

more info here:

    http://www.brunningonline.net/simon/blog/archives/000710.html
    http://www.python.org/doc/current/tut/node14.html

(also see the "floating point number problem" thread)

</F>








More information about the Python-list mailing list