Message78141
> Martin, that gives some answers like round(51, -2) --> 0 instead of 100.
I see. Here is a version that fixes that.
def round(n, i):
i = 10**(-i)
r = n%(2*i)
o = i/2
n -= r
if r <= o:
return n
elif r < 3*o:
return n+i
else:
return n+2*i
However, I now see that it is pointless not to use divrem, since
% computes the quotient as a side effect. |
|
Date |
User |
Action |
Args |
2008-12-21 09:30:56 | loewis | set | recipients:
+ loewis, rhettinger, mark.dickinson, giampaolo.rodola, jyasskin, dingo |
2008-12-21 09:30:54 | loewis | link | issue4707 messages |
2008-12-21 09:30:54 | loewis | create | |
|