```python
x = 3.5
y = int(x)
print(y) 输出为3
2. 使用 `math.floor()` 函数进行向下取整。
```python
import math
x = 3.5
y = math.floor(x)
print(y) 输出为3
3. 使用 `math.ceil()` 函数进行向上取整。
```python
import math
x = 3.5
z = math.ceil(x)
print(z) 输出为4
4. 使用 `round()` 函数对浮点数进行四舍五入,然后再转换为整数。
```python
x = 3.5
y = round(x)
print(y) 输出为4
5. 使用整数除法 `//` 进行向下取整。
```python
result = 10 // 3
print(result) 输出结果为3
6. 使用 `math.modf()` 函数分别获取整数部分和小数部分。
```python
import math
x = 3.25
integer_part, fractional_part = math.modf(x)
print(integer_part) 输出为3.0
根据你的具体需求,可以选择合适的方法来保留整数