148 |
# Comify a number |
# Comify a number |
149 |
# (e.g., print -9900 as -9,900.00) |
# (e.g., print -9900 as -9,900.00) |
150 |
def comify(num, decimals=2, parenthesis=0): |
def comify(num, decimals=2, parenthesis=0): |
151 |
|
neg = num < 0 |
152 |
|
num = abs(num) |
153 |
whole, dec = (string.split(string.strip(("%%12.%sf" % decimals) % abs(num)),'.') + [""])[:2] |
whole, dec = (string.split(string.strip(("%%12.%sf" % decimals) % abs(num)),'.') + [""])[:2] |
154 |
if len(dec): |
if len(dec): |
155 |
dec = "." + dec |
dec = "." + dec |
165 |
while s[:1] == ',': |
while s[:1] == ',': |
166 |
s = s[1:] |
s = s[1:] |
167 |
|
|
168 |
if num < 0: |
if neg: |
169 |
if parenthesis: |
if parenthesis: |
170 |
s = "(%s)" % s |
s = "(%s)" % s |
171 |
else: |
else: |