If you working with numpy, you can use the following solution which also works with negative numbers (it's also working on arrays)
import numpy as np
def round_down(num):
if num < 0:
return -np.ceil(abs(num))
else:
return np.int32(num)
round_down = np.vectorize(round_down)
round_down([-1.1, -1.5, -1.6, 0, 1.1, 1.5, 1.6])
> array([-2., -2., -2., 0., 1., 1., 1.])
I think it will also work if you just use the math
module instead of numpy
module.