文章目录
1. int(): 向下取整; 3.7取3;
2. math.ceil(): 向上取整; 3.2取4;
3. round(): 四舍五入;
4. math.modf(): 取整数部分和小数部分,返回一个元组:(小数部分,整数部分)。注意小数部分的结果有异议
import math
flo1 = 3.1415
flo2 = 3.500
flo3 = 3.789
print(int(flo1),math.ceil(flo1),round(flo1),math.modf(flo1))
print(int(flo2),math.ceil(flo2),round(flo2),math.modf(flo2))
print(int(flo3),math.ceil(flo3),round(flo3),math.modf(flo3))
"""
int ceil round modf
3 4 3 (0.14150000000000018, 3.0)
3 4 4 (0.5, 3.0)
3 4 4 (0.7890000000000001, 3.0)
"""
参考:https://www.cnblogs.com/huangqihui/p/12125109.html