Loading

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

posted @ 2022-03-27 08:54  ZXYFrank  阅读(142)  评论(0编辑  收藏  举报