Skip to main content
 首页 » 编程设计

python之为什么 math.ceil 返回一个 float

2025年05月04日10xiaohuochai

<分区>

Possible Duplicate:
Why do Python's math.ceil() and math.floor() operations return floats instead of integers?

来自 math.ceil 的 Python 文档...

math.ceil(x)
    Return the ceiling of x as a float, the smallest integer value greater than or equal to x.

为什么他们认为 float 更好?毕竟,根据定义,数字的 ceil 是一个整数,需要实数的操作可以很容易地从 int 转换为 float,但不一定相反,例如[0] * ceil(x) 的情况。