编程语言
首页 > 编程语言> > Python当中int 和 floor/ceil 的区别

Python当中int 和 floor/ceil 的区别

作者:互联网

floor() rounds down. int() truncates. The difference is clear when you use negative numbers:

>>> import math
>>> math.floor(-3.5)
-4
>>> int(-3.5)
-3

Rounding down on negative numbers means that they move away from 0, truncating moves them closer to 0.

Putting it differently, the floor() is always going to be lower or equal to the original. int() is going to be closer to zero or equal.

https://stackoverflow.com/questions/31036098/what-is-the-difference-between-int-and-floor-in-python-3

标签:closer,floor,Python,negative,ceil,int,3.5,numbers
来源: https://www.cnblogs.com/zxyfrank/p/16061890.html