python中浮点数取整

python中浮点数取整,第1张

1.向下取整
采用int强转即为向下取整

b = int(7.2) # 7
d = int(5.9) # 5

2.向上取整
math中的ceil函数

import math
print(math.ceil(4.1)) #5
print(math.ceil(4.9)) #5

3.四舍五入
round()函数

print(round(4.1)) #4
print(round(4.9)) #5

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/730288.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-27
下一篇2022-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存