如果您想从一个数字中提取多个。它就像我们在 excel 中有 Math.celling 一样工作。
def excel_celling(number=None, multiple_off=None):
quotient = number // multiple_off
reminder = number % multiple_off
celling_value = quotient * multiple_off + (multiple_off, 0)[reminder==0]
return int(celling_value)
assert excel_celling(99.99, 100) == 100, "True"
print(excel_celling(99.99, 100) , 100)
assert excel_celling(1, 100) == 100, "True"
print(excel_celling(1, 100),100)
assert excel_celling(99, 100) == 100, "True"
print(excel_celling(99, 100),100)
assert excel_celling(90, 100) == 100, "True"
print(excel_celling(90, 100),100)
assert excel_celling(101, 100) == 200, "True"
print(excel_celling(101, 100),200)
assert excel_celling(199, 100) == 200, "True"
print(excel_celling(199, 100),200)
assert excel_celling(199.99, 100) == 200, "True"
print(excel_celling(199.99, 100),200)
assert excel_celling(200, 100) == 200, "True"
print(excel_celling(200, 100),200)
结果
100 100
100 100
100 100
100 100
200 200
200 200
200 200
200 200