round issue

Emile van Sebille emile at fenx.com
Mon Jul 12 14:15:28 EDT 2010


On 7/12/2010 2:52 AM Robin Becker said...
<snip>
> What value should round(-9.85,1) return?

Per round's definition, -9.9.  String interpolation for %n.mf doesn't 
appear to define it's rounding behavior, so a peek at the source would 
answer what's being done.

It does look inconsistent however, and it seems to me rounding and 
interpolation should behave similarly.  So I'd call it a bug.

Emile



 >>> def display(val):
...   print "%.1f" % val
...   print round(val,1)
...
 >>> display(1.45)
1.5
1.5
 >>> display(-1.45)
-1.5
-1.5
 >>> display(-1.85)
-1.9
-1.9
 >>> display(1.85)
1.9
1.9
 >>> display(-7.85)
-7.8
-7.9
 >>> display(-9.85)
-9.8
-9.9
 >>>






More information about the Python-list mailing list