print(‘{:.3f} {:.2f}‘.format(1.23456,0.1256))#1.235 0.13
:.3f :3f表示保留3位有效数字
print(format(1.2345,‘.2f‘))#1.23
.2f :表示小数点后保留两位有效数字
使用了占位符{}可以同时输出多个,后者一次只能输出一个,需要注意的是占位符中的冒号不能丢
print(‘%.2f‘%1.2356)#1.24
print(round(1.2345,3))#1.234
print(round(2.3568,2))#2.36
#大于等于六时进位
print(round(2.9))#3
print(round(2.6))#3
print(round(2.5))#2
print(round(2.1))#2
原文:https://www.cnblogs.com/peng-blogs/p/14521182.html