views:

90

answers:

3

Hello,

I would like to create a function floor(number, step), which acts like :

floor(0, 1) = 0
floor(1, 1) = 1
floor(1, 2) = 0
floor(5, 2) = 4
floor(.8, .25) = .75

What is the better way to do something like that ?

Thanks.

+5  A: 

You could do something like floor( val / step ) * step

x4u
Thank you very much ! :)
Ttuff
+1  A: 

what you want is basically the same as

step * (x // step)

isn't ?

mykhal
A: 

Something along the lines of the code below ought to do the job.

def stepped_floor (n, step=1):
    return n - (n % step)
Vatine