在 Windows 7 Python 3.2 上,以下内容:
print(int(math.ceil(24/10)))
按预期给了我“3”。
在带有 Active Python 2.5 的 Windows Server 上,它给了我“2”。
这是什么问题,我该如何解决?
这是我的原始代码:
number_of_pages = int(math.ceil(number_of_rows/number_of_rows_per_page))
谢谢,
巴里
最佳答案
Python 2.x 使用截断除法,所以 24/10
的答案是 2。2 的 ceil
仍然是 2。
修复方法是将其中一个操作数转换为 float :
print(int(math.ceil(24.0/10)))
关于python - 可能的 math.ceil() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9726550/