This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author loewis
Recipients dingo, giampaolo.rodola, jyasskin, loewis, mark.dickinson, rhettinger
Date 2008-12-21.09:30:54
SpamBayes Score 0.0013673
Marked as misclassified No
Message-id <>
In-reply-to <>
> 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
        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:56loewissetrecipients: + loewis, rhettinger, mark.dickinson, giampaolo.rodola, jyasskin, dingo
2008-12-21 09:30:54loewislinkissue4707 messages
2008-12-21 09:30:54loewiscreate