logo

Python Number Floor() Method


Show

Description

The floor() method in Python number returns the floor of x where x is the largest integer but not greater than x. It is one of the Mathematical functions available in the Python math Library. The purpose of this function of Python Programming language is to return a value that is lesser than or is equal to a specific expression or value.

Syntax

Following is the syntax for floor() method:

import math

math.floor( x )

Note - This function is not accessible directly, so we need to import the math module, and then we need to call this function using a math static object.

Parameters

  • x - This is a numeric expression.

Return Value

This method returns the largest integer not greater than x.

Example

The following example shows the usage of floor() method.

#!/usr/bin/python
import math   # This will import math module

print "math.floor(-45.17) : ", math.floor(-45.17)
print "math.floor(100.12) : ", math.floor(100.12)
print "math.floor(100.72) : ", math.floor(100.72)
print "math.floor(119L) : ", math.floor(119L)
print "math.floor(math.pi) : ", math.floor(math.pi)

When we run the above program, it produces the following result:

math.floor(-45.17) :  -46.0
math.floor(100.12) :  100.0
math.floor(100.72) :  100.0
math.floor(119L) :  119.0
math.floor(math.pi) :  3.0

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.