您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页python如何不保留小数

python如何不保留小数

来源:伴沃教育

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

python学习网,大量的免费,欢迎在线学习!

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

相关推荐:《》

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

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务