[Python-bugs-list] [ python-Bugs-816946 ] Float Multiplication

SourceForge.net noreply at sourceforge.net
Mon Oct 6 06:08:16 EDT 2003


Bugs item #816946, was opened at 2003-10-03 05:09
Message generated for change (Settings changed) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=816946&group_id=5470

Category: Documentation
Group: Python 2.3
>Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Victor Demaria (vktor)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Float Multiplication

Initial Comment:
Why (1.16 * 100) is not the same than (1.16 * 10 * 10)?



I tried 1.16*100. also and it is = 115.99999999; but if I 

do 1.16*10*10 I get 116.



Thanks....





----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2003-10-06 11:07

Message:
Logged In: YES 
user_id=6656

Close again.

----------------------------------------------------------------------

Comment By: Victor Demaria (vktor)
Date: 2003-10-04 03:06

Message:
Logged In: YES 
user_id=879316

This is not a bug.



Binary floating point cannot represent decimal fractions exactly,

so some rounding always occurs (even in Python 1.5.2).



What changed is that Python 2.0 shows more precision than before

in certain circumstances (repr() and the interactive prompt). 



You can use str() or print to get the old, rounded output: 



>>> print 0.1+0.1

0.2

>>>



Follow the link for more information:



http://www.python.org/doc/2.2.1/tut/node14.html

----------------------------------------------------------------------

Comment By: Victor Demaria (vktor)
Date: 2003-10-04 03:06

Message:
Logged In: YES 
user_id=879316

I'sorry, but I don't agree...

Even 3.13 (3.1299999999999999) * 100 is 313 = like 

3.13*10*10 (3.13*100=3.13*10*10)

In this case 1.16*100 <> 1.16*10*10

Sorry again, but it is a huge difference when you do int

(1.16*100)=115  or you do int(1.16*10*10)=116

Thanks...

----------------------------------------------------------------------

Comment By: Fredrik Lundh (effbot)
Date: 2003-10-03 08:48

Message:
Logged In: YES 
user_id=38376

The answer to your question can be found in the Python 

tutorial, and has nothing to do with regular expressions:



http://www.python.org/doc/tut/node14.html



Please don't use the bug tracker to ask for help in the 

future; I suggest asking on comp.lang.python (for other 

help forums, see www.python.org).



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=816946&group_id=5470



More information about the Python-bugs-list mailing list