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