Floating point multiplication in python

Duncan Booth duncan.booth at invalid.invalid
Tue Sep 6 10:30:53 CEST 2011


Gary Herron <gherron at islandtraining.com> wrote:

> (But try:
>    print 1.1*1.1
> and see that the print statement does hide the roundoff error from you.)

That varies according to the version of Python you are using. On my system:

Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] 
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(1.1*1.1)
1.21
>>> ^Z


C:\Python27>cd \python32

C:\Python32>python
Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] 
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(1.1*1.1)
1.2100000000000002

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list