def commify(n):
    if n is None:
        return None
if type(n) is StringType:
    sepdec = localenv['mon_decimal_point']
else:
    sepdec = '.'
n = str(n)
if sepdec in n:
    dollars, cents = n.split(sepdec)
else:
    dollars, cents = n, None
r = []
for i, c in enumerate(reversed(str(dollars))):
    if i and not i % 3:
        r.insert(0, localenv['mon_thousands_sep'])
r.insert(0, c)
out = ''.join(r)
if cents:
    out += localenv['mon_decimal_point'] + cents
return out
python human readable large numbers