126 |
_thirdDollarMap = ('', 'Thousand ', 'Million ', 'Billion ', 'Trillion ') |
_thirdDollarMap = ('', 'Thousand ', 'Million ', 'Billion ', 'Trillion ') |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
# Comify a number |
131 |
|
# (e.g., print -9900 as -9,900.00) |
132 |
|
def comify(num, decimals=2, parenthesis=0): |
133 |
|
whole, dec = (string.split(string.strip(("%%12.%sf" % decimals) % abs(num)),'.') + [""])[:2] |
134 |
|
if len(dec): |
135 |
|
dec = "." + dec |
136 |
|
|
137 |
|
s = "" |
138 |
|
|
139 |
|
for i in range(divmod(len(whole),3)[0]+1): |
140 |
|
j = len(whole) - i*3 |
141 |
|
s = "," + whole[j > 3 and j-3 or 0:j] + s |
142 |
|
|
143 |
|
s += dec |
144 |
|
|
145 |
|
while s[:1] == ',': |
146 |
|
s = s[1:] |
147 |
|
|
148 |
|
if num < 0: |
149 |
|
if parenthesis: |
150 |
|
s = "(%s)" % s |
151 |
|
else: |
152 |
|
s = "-" + s |
153 |
|
elif parenthesis: |
154 |
|
s += " " |
155 |
|
|
156 |
|
return s |