Latest web development tutorials

Python ceil() 函數

Python 數字 Python數字


描述

ceil() 函數返回數字的上入整數。


語法

以下是ceil() 方法的語法:

import math

math.ceil( x )

注意: ceil()是不能直接訪問的,需要導入math模塊,通過靜態對象調用該方法。


參數

x -- 數值表達式。

返回值

函數返回數字的上入整數。

實例

以下展示了使用ceil() 方法的實例:

#!/usr/bin/python
import math   # This will import math module

print "math.ceil(-45.17) : ", math.ceil(-45.17)
print "math.ceil(100.12) : ", math.ceil(100.12)
print "math.ceil(100.72) : ", math.ceil(100.72)
print "math.ceil(119L) : ", math.ceil(119L)
print "math.ceil(math.pi) : ", math.ceil(math.pi)

以上實例運行後輸出結果為:

math.ceil(-45.17) :  -45.0
math.ceil(100.12) :  101.0
math.ceil(100.72) :  101.0
math.ceil(119L) :  119.0
math.ceil(math.pi) : 4.0

Python 數字 Python數字