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
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.