Issue 9885: Function Round does not work properly in some conditions (original) (raw)

Issue9885

Created on 2010-09-17 11:36 by paontis, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
round.txt paontis,2010-09-17 11:36 examples of round results
Messages (3)
msg116656 - (view) Author: (paontis) Date: 2010-09-17 11:36
For example round(10.3333, 1) returns 10.300000000000001 and round(1.3333, 2)returns 1.3300000000000001 I exect they return 10.3 and 1.33 rispectively NOTE: other combinations work fine eg. round(10.3333, 2) or round(1.3333, 3) See IDLE commands in the attached file round.txt Used Python 2.6.6 for Windows
msg116669 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-09-17 14:27
Please read http://docs.python.org/tutorial/floatingpoint.html Although your case isn't directly covered there, the root cause is the same. Floating point can't exactly represent 10.3. Note that in Python2.7 and 3.x, the repr will be shortened to 10.3, so if you'd tried this there you would never have noticed the underlying issue. If you need exact decimal arithmetic, use the Decimal module.
msg116670 - (view) Author: (paontis) Date: 2010-09-17 14:35
ok thx very much for the explaination
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54094
2010-09-17 14:35:56 paontis set messages: +
2010-09-17 14:27:58 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: not a bugstage: resolved
2010-09-17 11:36:16 paontis create