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的英文释义:地板。顾名思义也是向下取整
importmath n=3.75 print(math.floor(n)) >>>3 n=3.25 print(math.floor(n)) >>>3
4、ceil()向上取整 (math模块函数)
ceil的英文释义:天花板。
importmath n=3.75 print(math.ceil(n)) >>>4 n=3.25 print(math.ceil(n)) >>>4
下一篇