Python_round函数(小数的处理)
round函数对小数的处理:
1、设置保留多少位小数
2、会有四舍五入的处理
实例:
(1)保留n位小数
s = 1.234567
result = round(s, 2)
print(result)
1.23
(2)自动四舍五入
s = 1.23567
result = round(s, 2)
print(result)
1.24
>>> s = 1.234567 >>> result = round(s, 2) >>> print(result) 1.23
>>> s = 1.23567 >>> result = round(s, 2) >>> print(result) 1.24