我在Python中找到了两种发言方式:
3.1415 // 1
和
import math
math.floor(3.1415)
The problem with the first approach is that it return a float (namely 3.0
). The second approach feels clumsy 和 too long.
在Python中有没有其他解决方案?
我在Python中找到了两种发言方式:
3.1415 // 1
和
import math
math.floor(3.1415)
The problem with the first approach is that it return a float (namely 3.0
). The second approach feels clumsy 和 too long.
在Python中有没有其他解决方案?
只要你的数字是正数,你就可以简单地转换成int
,然后四舍五入到下一个整数:
>>> int(3.1415)
3
但是,对于负整数,这将向上取整.