Python| math.floor()函数
在Python中,数学模块包含许多数学运算,可以使用该模块轻松执行。 math.floor()
函数返回不大于 x 的最大整数。如果 number 已经是整数,则返回相同的数字。
Syntax: math.floor(x)
Parameter:
x: This is a numeric expression.
Returns: largest integer not greater than x.
代码#1:
# Python code to demonstrate the working of floor()
# importing "math" for mathematical operations
import math
x = 33.7
# returning the floor of 33.7
print ("The floor of 33.7 is : ", end ="")
print (math.floor(x))
输出:
The floor of 33.7 is : 33
代码#2:
# Python code to demonstrate the working of floor()
# importing "math" for mathematical operations
import math
# prints the floor using floor() method
print ("math.floor(-13.1) : ", math.floor(-13.1))
print ("math.floor(101.96) : ", math.floor(101.96))
输出:
math.floor(-13.1) : -14
math.floor(101.96) : 101