您的位置:首页 > 编程语言 > Python开发

python floor() 函数

2016-11-30 16:42 162 查看

Python floor() 函数

描述

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

可以和 ceil() 函数对比来记。

语法

import math
math.floor(x)


注意:floor() 函数是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。

参数

x 数值表达式

返回值

返回数字的下舍整数。

实例

# -*- coding: UTF-8 -*-

import 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(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: