How to create a gender function with a step argument

I would like to create a function gender (number, step) that 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 best way to do something like this?

Thanks.

+4
source share
3 answers

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

+6
source

what you want is basically the same as

step * (x // step)

not?

+2
source

Something according to the code below should be executed.

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

All Articles