"""
if n is None: return None
+
+ n = str(n)
+ if '.' in n:
+ dollars, cents = n.split('.')
+ else:
+ dollars, cents = n, None
+
r = []
- for i, c in enumerate(reversed(str(n))):
+ for i, c in enumerate(reversed(dollars)):
if i and (not (i % 3)): r.insert(0, ',') r.insert(0, c)
- return ''.join(r)
+ out = ''.join(r)
+ if cents:
+ out += '.' + cents
+ return out
Here's a patch:
diff --git a/web/utils.py b/web/utils.py
'1,234, 567,890'
index 73a2ba0..2bb5da9 100755
--- a/web/utils.py
+++ b/web/utils.py
@@ -636,17 +636,35 @@ def commify(n):
'1,234'
>>> commify(1234567890)
+ >>> commify(123.0)
+ '123.0'
+ >>> commify(1234.5)
+ '1,234.5'
+ >>> commify(1234.56789)
+ '1,234.56789'
+ >>> commify('%.2f' % 1234.5)
+ '1,234.50'
>>> commify(None)
>>>
""" reversed( str(n)) ): reversed( dollars) ):
r. insert( 0, ',')
r.insert( 0, c)
if n is None: return None
+
+ n = str(n)
+ if '.' in n:
+ dollars, cents = n.split('.')
+ else:
+ dollars, cents = n, None
+
r = []
- for i, c in enumerate(
+ for i, c in enumerate(
if i and (not (i % 3)):
- return ''.join(r)
+ out = ''.join(r)
+ if cents:
+ out += '.' + cents
+ return out
def dateify( datestring) :
"""