使用 NumPy 将数字舍入到最接近的千位,但仅向下
Round number with NumPy to the nearest thousand, but downward only
我正在寻找 np.round(234_567, -3)
的等价物,它将产生 Out[1]: 235000
。但是,我只想向下舍入。我想要的输出是:Out[1]: 234000
。
import numpy as np
number = 234_567 # find a way to round this downward to 234_000
round
四舍五入到最接近的偶数;要向下舍入,请改用 floor
。但是,由于它没有 decimals
参数,因此您需要自己执行此操作:
np.floor(234_567 / 1_000) * 1_000
或者,等价地
np.floor(234_567 / 10 ** 3) * 10 ** 3
我正在寻找 np.round(234_567, -3)
的等价物,它将产生 Out[1]: 235000
。但是,我只想向下舍入。我想要的输出是:Out[1]: 234000
。
import numpy as np
number = 234_567 # find a way to round this downward to 234_000
round
四舍五入到最接近的偶数;要向下舍入,请改用 floor
。但是,由于它没有 decimals
参数,因此您需要自己执行此操作:
np.floor(234_567 / 1_000) * 1_000
或者,等价地
np.floor(234_567 / 10 ** 3) * 10 ** 3