print('2.105:',round(2.105,2),'\n',
'2.115:',round(2.115,2),'\n',
'2.125:',round(2.125,2),'\n',
'2.135:',round(2.135,2),'\n',
'2.145:',round(2.145,2),'\n',
'2.155:',round(2.155,2),'\n',
'2.165:',round(2.165,2),'\n',
'2.175:',round(2.175,2),'\n',
'2.185:',round(2.185,2),'\n',
'2.195:',round(2.195,2))
输出:
2.105: 2.1
2.115: 2.12
2.125: 2.12
2.135: 2.13
2.145: 2.15
2.155: 2.15
2.165: 2.17
2.175: 2.17
2.185: 2.19
2.195: 2.19
找不到规律,最好别用,自己写
本文探讨了Python中使用round函数进行浮点数四舍五入时的潜在问题,展示了特定数值下可能产生的非预期结果,并建议开发者自行实现更精确的四舍五入算法。
1600

被折叠的 条评论
为什么被折叠?



