美文网首页Python Web开发学习
Python模块---向上向下取整、四舍五入取整

Python模块---向上向下取整、四舍五入取整

作者: 吾星喵 | 来源:发表于2019-02-11 12:57 被阅读0次

向上向下取整、四舍五入取整

import math

# 向上取整
math.ceil(2.3)
3
math.ceil(2.6)
3

# 向下取整
math.floor(2.3)
2
math.floor(2.6)
2

# 四舍五入
round(2.3)
2
round(2.6)
3

# 返回值都是整型
a = math.ceil(2.3)
type(a)
# <class 'int'>

b = math.floor(2.3)
type(b)
# <class 'int'>

相关文章

网友评论

    本文标题:Python模块---向上向下取整、四舍五入取整

    本文链接:https://www.haomeiwen.com/subject/iehqeqtx.html