Python3 floor() Function
Description
floor(x) returns the floor of a number, an integer less than or equal to x.
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
- x -- a numeric expression.
Return Value
Returns an integer less than or equal to x.
Example
The following shows examples of using the floor() method:
#!/usr/bin/python
import math # 导入 math 模块
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(math.pi) : ", math.floor(math.pi))
Running the example above produces:
math.floor(-45.17) : -46
math.floor(100.12) : 100
math.floor(100.72) : 100
math.floor(math.pi) : 3
Python3 Numbers