What is math.ceil() in Python?

The ceil() function returns the nearest smallest integer greater than or equal to a number. Figure 1 shows the mathematical representation of the ceil() function.

Figure 1: Mathematical representation of ceil() function

The math module is required for this function.

Syntax

ceil(number)

Parameter

This function requires a number to round up as a parameter.

Return value

ceil() returns the nearest smallest integer greater than or equal to a number sent as a parameter.

Example

import math
#positive integer sent as parameter
print "ceil(10) : ", math.ceil(10)
#negative integer sent as parameter
print "ceil(-10) : ", math.ceil(-10)
#positive float value sent as parameter
print "ceil(2.1) : ", math.ceil(2.1)
#negative float value sent as parameter
print "ceil(-2.1) : ", math.ceil(-2.1)

Free Resources