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

Python floor() function

Python floor() function

Python Numbers Python Numbers


Description

floor() returns the floor of a number (the largest integer less than or equal to it).


Syntax

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



import math



math.floor( x )

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


Parameters


Return Value

Returns the floor of a number.


Example

The following shows examples of using the 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)

Running the example above produces:



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

Python Numbers Python Numbers