方法:
f = 1.23456
print('%.4f' % f)
print('%.3f' % f)
print('%.2f' % f)
print(format(1.23456, '.2f'))
print(format(1.23456, '.3f'))
print(format(1.23456, '.4f'))
a = 1.23456
b = 2.355
c = 3.5
d = 2.5
print(round(a, 3))
print(round(b, 2))
print(round(c))
print(round(d))
参考链接:
https://blog.csdn.net/liuweiyuxiang/article/details/100574386