Precision Issue

Tim Peters tim.one at home.com
Fri Aug 3 13:49:12 EDT 2001


[Casey Stein]
> So I'm going through the Python tutorial and I get to the part on
> lists, queues and such and the following happens:
>
> >>> a = [66.6, 333, 333, 1, 1234.5]
> >>> print a.count(333), a.count(66.6), a.count('x')
> 2 1 0
> >>> a.insert(2, -1)
> >>> a.append(333)
> >>> a
> [66.599999999999994, 333, -1, 333, 1, 1234.5, 333]
> >>> print a
> [66.599999999999994, 333, -1, 333, 1, 1234.5, 333]
> >>> print a.count(66.6)
> 1
> >>>
>
> Why is it converting my 66.6 to 66.599999999999994?

There's a gentle explanation in the development version of the Python
Tutorial, here:

    http://python.sourceforge.net/devel-docs/tut/node14.html





More information about the Python-list mailing list