python ceil()函数介绍
ceil()函数返回值上限的X - 不小于x的最小整数。
语法:
import math
math.ceil( x )
注:此功能是不能直接访问的,所以我们需要导入的数学模块,然后我们需要调用这个函数,用数学的静态对象。
参数:
X:这是一个数值表达式。
返回值:不小于x的最小整数。
python ceil()实例:
对数值进行向上取整:
import math
#向上取整
print "math.ceil---"
print "math.ceil(2.3) => ", math.ceil(2.3)
print "math.ceil(2.6) => ", math.ceil(2.6)
输出结果:
math.ceil---
math.ceil(2.3) => 3.0
math.ceil(2.6) => 3.0
再如:
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)
/* http://www.manongjc.com/article/1335.html */
输出结果:
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