Ticket #3017: commaseparate.2.patch
File commaseparate.2.patch, 2.1 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 return intcomma(new) 31 return commaseparate(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
87 87 88 88 You can pass in either an integer or a string representation of an integer. 89 89 90 intcomma 91 -------- 90 commaseparate 91 ------------- 92 92 93 Converts an integer to a string containing commas every three digits. 93 **New in Django development version**: ``commaseparate`` (which was previously 94 called ``intcomma``) now works with both integers and floating point numbers. 94 95 96 Converts a number to a string containing commas every three digits (before any 97 decimal place). 98 95 99 Examples: 96 100 97 101 * ``4500`` becomes ``'4,500'``. 98 102 * ``45000`` becomes ``'45,000'``. 99 103 * ``450000`` becomes ``'450,000'``. 100 104 * ``4500000`` becomes ``'4,500,000'``. 105 * ``4500.0001`` becomes ``'4,500.0001'``. 101 106 102 You can pass in either an integer or a string representation of an integer. 107 You can pass in either an integer, a float or a string representation of an 108 integer or float. 103 109 104 110 intword 105 111 -------