Martin v. Löwis <mar...@v.loewis.de> added the comment:

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

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue4707>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to