我有以下数字,我要转换:
'2.44' --> '2.44'
'12.83' --> '2.83'
'121.834' --> '1.83'
换句话说,我想要小数点左边的一位数字和右边的两位数字。最好的方法是什么?我当前的方法是使用:
number = '41.33'
index = number.index('.')
result = number[index-1] + '.' + number[index+1:index+3]
有没有更好,更清洁的方法来做到这一点?
result = number[index - 1: index + 3]
就这些
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句