Latest web development tutorials

Python3 floor () function

Python3 digital Python3 digital


description

floor (x) Returns the rounded integer less than or equal to x.


grammar

The following is the syntax floor () method:

import math

math.floor( x )

NOTE: floor () is not directly accessible, we need to import math module, invoke the method through static object.


parameter

  • x - numeric expression.

return value

Returns an integer less than or equal to x.

Examples

The following shows an example of using 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 output is:

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

Python3 digital Python3 digital