美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联Python教程:python如何不保留小数

1、int() 向下取整(内置函数) 

python学习网,大量的免费python视频教程,欢迎在线学习!

n = 3.75
print(int(n))
>>> 3
n = 3.25
print(int(n))
>>> 3

相关推荐:《Python基础教程》

2、round() 四舍五入(内置函数) 

n = 3.75
print(round(n))
>>> 4
n = 3.25
print(round(n))
>>> 3

3、floor() 向下取整(math模块函数) 

floor的英文释义:地板。顾名思义也是向下取整

import math
n = 3.75
print(math.floor(n))
>>> 3
n = 3.25
print(math.floor(n))
>>> 3

4、ceil()向上取整 (math模块函数)

ceil的英文释义:天花板。

import math
n = 3.75
print(math.ceil(n))
>>> 4
n = 3.25
print(math.ceil(n))
>>> 4

当前文章:创新互联Python教程:python如何不保留小数
文章链接:http://zsjierui.cn/article/djdiocs.html

其他资讯