Python ceil() function

Python 数字Python Numbers


Description

The ceil() function returns the ceiling integer of a number.


Syntax

The following is the syntax of the ceil() method:

import math

math.ceil( x )

Note:ceil() is not directly accessible; you need to import the math module and call the method through a static object.


Parameters

x -- A numeric expression.

Return Value

The function returns the ceiling integer of the number.

Examples

The following shows examples of using the ceil() method:

#!/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)

After running the above examples, the output result is:

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 Numbers

Other Extensions