python 保留两位小数
import random
data1 = random.uniform(0, 100)
data2 = random.uniform(0, 100)
data3 = random.uniform(0, 100)
data4 = random.uniform(0, 100)
print(data1)
print(f'结果1是:{data1:.2f}')
print(data2)
print('结果2是:{:.2f}'.format(data2))
print(data3)
print('结果3是:%.2f' % data3)
print(data4)
print('结果4是:' + str(round(data4, 2)))
"""
3.1986171366035654
结果1是:3.20
29.59742212547066
结果2是:29.60
97.8929441763928
结果3是:97.89
33.46026106618613
结果4是:33.46
"""