[Tutor] Floating Confusion

wormwood_3 wormwood_3 at yahoo.com
Thu Aug 23 02:08:01 CEST 2007


Dear Tutors,

Reading through Wesley's delightful Core Python Programming, I came across something I have not been able to grasp yet. Some introductory code:

>>> 1
1
>>> 1.1
1.1000000000000001
>>> print 1
1
>>> print 1.1

1.1


The second case is, of course, what is throwing me. By having a decimal point, "1.1" is a float type, and apparently it cannot be represented by binary floating point numbers accurately. I must admit that I do not understand why this is the case. Would anyone be able to enlighten me?

-Sam





More information about the Tutor mailing list