Python 之 向上取整、向下取整、四舍五入函数

1. 向上取整

import math

f = 11.2
print math.ceil(f) #向上取整

out:12.0  # 返回结果是浮点型

2.向下取整

import math

f = 11.2
print math.floor(f) #向下取整

out: 11.0  #返回结果是浮点型

3. 四舍五入

import math

f = 11.2
print round(f) #四舍五入

out: 11.0  #返回结果是浮点型

4.参考

https://www.cnblogs.com/SZxiaochun/p/6961370.html

发布了38 篇原创文章 · 获赞 98 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/xijuezhu8128/article/details/88554887