Ticket #3017: commaseparate.patch
File commaseparate.patch, 1.9 KB (added by , 18 years ago) |
---|
-
django/contrib/humanize/templatetags/humanize.py
18 18 return '%d%s' % (value, t[value % 10]) 19 19 register.filter(ordinal) 20 20 21 def intcomma(value):21 def commaseparate(value): 22 22 """ 23 Converts an integer to a string containing commas every three digits.23 Converts an number to a string containing commas every three digits. 24 24 For example, 3000 becomes '3,000' and 45000 becomes '45,000'. 25 25 """ 26 26 orig = str(value) 27 new = re.sub("^(-?\d+)(\d{3}) ", '\g<1>,\g<2>', str(value))27 new = re.sub("^(-?\d+)(\d{3})((?:\.\d+)?)", r'\1,\2\3', str(value)) 28 28 if orig == new: 29 29 return new 30 30 else: 31 31 return intcomma(new) 32 register.filter(commaseparate) 33 34 # Backwards compatibility (commaseparate used to be called intcomma). 35 intcomma = commaseparate 32 36 register.filter(intcomma) 33 37 34 38 def intword(value): -
docs/add_ons.txt
70 70 71 71 You can pass in either an integer or a string representation of an integer. 72 72 73 intcomma 74 -------- 73 commaseparate 74 ------------- 75 75 76 Converts an integer to a string containing commas every three digits. 76 Converts a number to a string containing commas every three digits (before any 77 decimal place). 77 78 78 79 Examples: 79 80 … … 81 82 * ``45000`` becomes ``'45,000'``. 82 83 * ``450000`` becomes ``'450,000'``. 83 84 * ``4500000`` becomes ``'4,500,000'``. 85 * ``4500.0001`` becomes ``'4,500.0001'``. 84 86 85 You can pass in either an integer or a string representation of an integer. 87 You can pass in either an integer, a float or a string representation of an 88 integer or float. 86 89 87 90 intword 88 91 -------