有谁知道比这更简单的方法来使数字具有数千个分隔符:
def addComma(num):
(num, post) = str(num).split('.')
num = list(num)
num.reverse()
count = 0
list1 = []
for i in num:
count += 1
if count % 3 == 0:
list1.append(i)
list1.append(',')
else:
list1.append(i)
list1.reverse()
return ''.join(list1).strip(',') + '.' + post
它有效,但它似乎真的很脆弱......