What is math.floor() in Python?

The floor() function returns the next largest integer less than or equal to a number. Figure 1 below shows the mathematical representation of the floor() function.

Figure 1: Mathematical representation of floor() function

The math module is required for this function.

Syntax

floor(number)

Parameter

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

Return value

The floor() function returns the next largest integer less than or equal to the number set as a parameter.

Example

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

Free Resources