Ticket #13810: number_format_r13401.patch

File number_format_r13401.patch, 1.8 KB (added by Łukasz Rekucki, 14 years ago)
  • django/utils/numberformat.py

    diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
    index 129c27f..4fd4741 100644
    a b  
    11from django.conf import settings
    22
    3 def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''):
     3def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''):
    44    """
    55    Gets a number (as a number or string), and returns it as a string,
    66    using formats definied as arguments:
    def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''):  
    2222        str_number = str_number[1:]
    2323    if '.' in str_number:
    2424        int_part, dec_part = str_number.split('.')
    25         if decimal_pos:
     25        if decimal_pos is not None:
    2626            dec_part = dec_part[:decimal_pos]
    2727    else:
    2828        int_part, dec_part = str_number, ''
    29     if decimal_pos:
     29    if decimal_pos is not None:
    3030        dec_part = dec_part + ('0' * (decimal_pos - len(dec_part)))
    3131    if dec_part: dec_part = decimal_sep + dec_part
    3232    # grouping
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index 32c991a..6cb35d0 100644
    a b class FormattingTests(TestCase):  
    143143        settings.USE_THOUSAND_SEPARATOR = False
    144144        self.assertEqual(u'66666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
    145145        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'))
    146147
    147148        settings.USE_THOUSAND_SEPARATOR = True
    148149        self.assertEqual(u'66,666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
Back to Top