Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python ceil() function

Python ceil() function

Python Numbers Python Numbers


Description

The ceil() function returns the ceiling of a number (the smallest integer greater than or equal to it).


Syntax

The syntax of the ceil() method is as follows:



import math



math.ceil( x )

**Note:** ceil() cannot be accessed directly; you need to import the math module and call the method through the static object.


Parameters

x -- a numeric expression.


Return Value

Returns the ceiling of a number.


Example

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)

Running the example above produces:



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 Numbers Python Numbers