If you work with numpy, you can use the following solution, which also works with negative numbers (it also works with 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 this will also work if you just use the math module instead of the numpy module.
Mr Poin Jun 22 '16 at 21:34 2016-06-22 21:34
source share