Rounding

P at draigBrady.com P at draigBrady.com
Tue Nov 4 07:13:25 EST 2003


Zunbeltz Izaola wrote:
> Hi to all!
> 
> I want to know if it is possible to round a floating number to
> multiples of another number. An example:
> I've spam = 0.36 and foo = 0.38 and i want something like this:
> 
> 
>>>>round(spam,0.25)
> 
> 0.25
> 
>>>>round(foo,0.25)
> 
> 0.50
> 
> I know that builtin round rounds to a decimal position, but is there a
> module (or it is easy to code) with a function like this?

def roundto(num,round_multiple):
     return round(num/round_multiple)*round_multiple

Pádraig.





More information about the Python-list mailing list