Data type sequence error:Dictionary

Derek Thomson derek.thomson at gmail.com
Wed Jul 28 04:27:31 EDT 2004


On Wed, 28 Jul 2004 15:56:00 +0800, BlackWhite <live1024 at hotmail.com> wrote:
> [3.1400..01,42,9]            //Why 3.140000000000000001 should not have 1 in
> the end
> 
> Why this happened?

I just realized you were asking two questions there ...

The reason 3.14 didn't get returned as exactly 3.14 is that, in
Python, real numbers are represented in "floating point." This is a
particular scheme for storing numbers in computers that, while
allowing the representation of very large and very small real numbers
and at the same time staying within a strict size, sacrifices the
ability to exactly represent all possible numbers. 3.14 is one of
those numbers.

Wikipedia has an article on floating point numbers here:
http://en.wikipedia.org/wiki/Floating_point

If you can't live with this restriction, you may have to use some
other representation. I'm not sure which (if any) are available with
Python, so someone else will have to weigh in there.

dt.



More information about the Python-list mailing list