Possible Duplicate:
how to print number with commas as thousands separators in Python 2.x
Does anyone know of an easier way to make numbers have thousands separation than this:
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
It works, but it seems REALLY fragile...