python floor() returns the rounded down integer of a number.
The following is the syntax of the floor() method:
import math math.floor( x )
Note: floor() cannot be accessed directly. You need to import the math module and call the method through a static object. .
Parameters
x -- Numeric expression.
Return value
Returns the rounded integer of the number.
The following shows an example 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)
The output result after running the above example is:
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
Related recommendations: "Python Tutorial》
The above is the detailed content of How to use floor in python. For more information, please follow other related articles on the PHP Chinese website!