Ticket #9037: humanize_intdot.diff
File humanize_intdot.diff, 2.4 KB (added by , 16 years ago) |
---|
-
django/contrib/humanize/templatetags/humanize.py
37 37 intcomma.is_safe = True 38 38 register.filter(intcomma) 39 39 40 def intdot(value): 41 """ 42 Converts an integer to a string containing dots every three digits. 43 For example, 3000 becomes '3.000' and 45000 becomes '45.000'. 44 """ 45 orig = force_unicode(value) 46 new = re.sub("^(-?\d+)(\d{3})", '\g<1>.\g<2>', orig) 47 if orig == new: 48 return new 49 else: 50 return intdot(new) 51 intdot.is_safe = True 52 register.filter(intdot) 53 40 54 def intword(value): 41 55 """ 42 56 Converts a large integer to a friendly text representation. Works best for -
tests/regressiontests/humanize/tests.py
37 37 38 38 self.humanize_tester(test_list, result_list, 'intcomma') 39 39 40 def test_intdot(self): 41 test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25, 42 '100', '1000', '10123', '10311', '1000000', '1234567.1234567') 43 result_list = ('100', '1.000', '10.123', '10.311', '1.000.000', '1.234.567.25', 44 '100', '1.000', '10.123', '10.311', '1.000.000', '1.234.567.1234567') 45 46 self.humanize_tester(test_list, result_list, 'intdot') 47 40 48 def test_intword(self): 41 49 test_list = ('100', '1000000', '1200000', '1290000', 42 50 '1000000000','2000000000','6000000000000') -
docs/ref/contrib/humanize.txt
42 42 43 43 You can pass in either an integer or a string representation of an integer. 44 44 45 intdot 46 ------ 47 48 Converts an integer to a string containing dots every three digits. 49 50 Examples: 51 52 * ``4500`` becomes ``'4.500'``. 53 * ``45000`` becomes ``'45.000'``. 54 * ``450000`` becomes ``'450.000'``. 55 * ``4500000`` becomes ``'4.500.000'``. 56 57 You can pass in either an integer or a string representation of an integer. 58 45 59 intword 46 60 ------- 47 61