Rounding to the nearest 5

Miles semanticist at gmail.com
Fri Jan 30 06:43:27 CET 2009


On Thu, Jan 29, 2009 at 7:26 PM, Tim Chase wrote:
>> How can you make python round numbers to the nearest 5:
>>  Example:
>>  3 => 0
>> 8 => 10
>> 23.2 => 20
>> 36 => 35
>> 51.5 => 50
>
> I'm not sure *any* rounding system will give those results.

def bogoround(n):
    n1 = n / 5.0
    return int(round(n1) if n1 % 2 > 1 else n1) * 5

best-I-could-do-ly y'rs,
-Miles



More information about the Python-list mailing list