[Python-bugs-list] [ python-Bugs-501288 ] problems with divising

noreply@sourceforge.net noreply@sourceforge.net
Wed, 09 Jan 2002 10:42:14 -0800


Bugs item #501288, was opened at 2002-01-09 05:28
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=501288&group_id=5470

Category: Python Interpreter Core
Group: Not a Bug
>Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Zsolt Cserna (csernazs)
Assigned to: Tim Peters (tim_one)
Summary: problems with divising

Initial Comment:
I have problems with divising (int/float) in python
2.1.1. For example, if I try divide two numbers
(45/100.0), the result of this will be not correct.

>>> 45/100.0
0.45000000000000001

Python 2.1.1+ (#1, Jan  8 2002, 00:37:12) 
[GCC 2.95.4 20011006 (Debian prerelease)] on linux2

With python 1.5 it works correctly.

Thanks for help.



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

Comment By: Tim Peters (tim_one)
Date: 2002-01-09 10:40

Message:
Logged In: YES 
user_id=31435

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://python.sourceforge.net/devel-docs/tut/node14.html

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

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