The Python rounding up, rounding down, rounding function

1. improvement ToSei

import math

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

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

2. Rounding down

import math

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

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

3. rounding

import math

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

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

4. Reference

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

 

Published 38 original articles · 98 won praise · views 360 000 +

Guess you like

Origin blog.csdn.net/xijuezhu8128/article/details/88554887