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 <494E0CCB.7080403@v.loewis.de>
In-reply-to <1229821749.19.0.0927573434533.issue4707@psf.upfronthosting.co.za>
Content
> 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.
History
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