Python math.floor() 方法
示例
將數字向下舍入到最接近的整數
# 匯入 math 庫
import math
# 將數字向下舍入到最接近的整數
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
自己動手試一試 »
定義和用法
math.floor()
方法將數字向下舍入到最接近的整數(如果需要),並返回結果。
提示:要將數字向上舍入到最接近的整數,請檢視 math.ceil()
方法。
語法
math.floor(x)
引數值
引數 | 描述 |
---|---|
x | 必需。指定要向下舍入的數字 |
技術詳情
返回值 | 一個 int 值,表示舍入後的數字 |
---|---|
更改日誌 | Python 3+:返回一個 int 值Python 2.x:返回一個 float 值 |