Python3 floor() function

Python3 数字Python3 Numbers


Description

floor(x) returns the floor integer of a number, which is less than or equal to x.


Syntax

The following is the syntax for the floor() method:

import math

math.floor( x )

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


Parameters

  • x -- A numeric expression.

Return Value

Returns an integer less than or equal to x.

Example

The following shows an example 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))

After running the above example, the output result is:

math.floor(-45.17) :  -46
math.floor(100.12) :  100
math.floor(100.72) :  100
math.floor(math.pi) :  3

Python3 数字Python3 Numbers

Other Extensions