python如何不保留小数
爱喝马黛茶的安东尼
2019-12-21 09:24:0819218浏览 · 0收藏 · 0评论
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
关注公众号,随时随地在线学习