diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
index 129c27f..4fd4741 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | |
3 | | def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''): |
| 3 | def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''): |
4 | 4 | """ |
5 | 5 | Gets a number (as a number or string), and returns it as a string, |
6 | 6 | using formats definied as arguments: |
… |
… |
def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''):
|
22 | 22 | str_number = str_number[1:] |
23 | 23 | if '.' in str_number: |
24 | 24 | int_part, dec_part = str_number.split('.') |
25 | | if decimal_pos: |
| 25 | if decimal_pos is not None: |
26 | 26 | dec_part = dec_part[:decimal_pos] |
27 | 27 | else: |
28 | 28 | int_part, dec_part = str_number, '' |
29 | | if decimal_pos: |
| 29 | if decimal_pos is not None: |
30 | 30 | dec_part = dec_part + ('0' * (decimal_pos - len(dec_part))) |
31 | 31 | if dec_part: dec_part = decimal_sep + dec_part |
32 | 32 | # grouping |
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 32c991a..6cb35d0 100644
a
|
b
|
class FormattingTests(TestCase):
|
143 | 143 | settings.USE_THOUSAND_SEPARATOR = False |
144 | 144 | self.assertEqual(u'66666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=',')) |
145 | 145 | self.assertEqual(u'66666A6', nformat(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B')) |
| 146 | self.assertEqual(u'66666', nformat(self.n, decimal_sep='X', decimal_pos=0, grouping=1, thousand_sep='Y')) |
146 | 147 | |
147 | 148 | settings.USE_THOUSAND_SEPARATOR = True |
148 | 149 | self.assertEqual(u'66,666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=',')) |