gpt4 book ai didi

python - python 中类似 Excel 的上限函数?

转载 作者:太空狗 更新时间:2023-10-29 20:54:50 24 4
gpt4 key购买 nike

我知道 math.ceilnumpy.ceil , 但它们都缺少 significance 参数。例如在 Excel 中:

=Ceiling(210.63, 0.05) -> 210.65

numpy.ceil 和 math.ceil 在另一方面:

numpy.ceil(210.63) -> 211.0

math.ceil(210.63) -> 211.0

所以,我想知道,是否已经有类似Excel的解决方案了?

最佳答案

我不知道有任何 python 函数可以这样做,但您可以轻松编写一个代码:

import math

def ceil(x, s):
return s * math.ceil(float(x)/s)

如果两个参数都是整数,则在 python 2 中必须转换为 float 以避免整数除法。您还可以使用 from __future__ import division。 python 3 不需要这个。

关于python - python 中类似 Excel 的上限函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7672107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com