1. 向下取整(Flooring):
使用内置函数 `int()`。
例如:`int(3.75)` 返回 `3`。
2. 向上取整(Ceiling):
使用 `math` 模块中的 `math.ceil()` 函数。
例如:`math.ceil(3.75)` 返回 `4`。
3. 四舍五入(Rounding):
使用内置函数 `round()`。
例如:`round(4.4)` 返回 `4`,`round(4.6)` 返回 `5`。
4. 分别取整数部分和小数部分:
使用 `math` 模块中的 `math.modf()` 函数。
例如:`math.modf(4.25)` 返回一个元组 `(0.25, 4.0)`,其中 `0.25` 是小数部分,`4.0` 是整数部分。
5. 使用 `//` 运算符进行整除,效果为向下取整。
例如:`5 // 2` 返回 `2`。
请根据你的具体需求选择合适的取整方法