Python floor() 函数舍弃小数位

时间:2016-08-16
Python floor()函数用于获取数字的下舍整数,即舍弃数字小数位,本文章向大家介绍Python floor() 函数的使用方法和实例,需要的朋友可以参考一下。

python floor()函数介绍

floor() 返回数字的下舍整数。

语法:

import math
math.floor( x )

注:此功能是不能直接访问的,所以我们需要导入的数学模块,然后我们需要调用这个函数,用数学的静态对象。

参数:

  1. X:这是一个数值表达式。

返回值: 

最大的整数不大于X

python floor()函数实例

#!/usr/bin/python
import math   # This will import math module
#  http://www.manongjc.com/article/1361.html 
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)

这将输出以下结果:

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