Ticket #17414: 17414-1.diff

File 17414-1.diff, 1.6 KB (added by Claude Paroz, 12 years ago)

Fix possible ZeroDivisionError in numberformat

  • django/utils/numberformat.py

    diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
    index c6528c0..6418406 100644
    a b def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', f  
    1313    * thousand_sep: Thousand separator symbol (for example ",")
    1414
    1515    """
    16     use_grouping = force_grouping or settings.USE_L10N and \
    17         settings.USE_THOUSAND_SEPARATOR and grouping
     16    use_grouping = (force_grouping or settings.USE_L10N and
     17        settings.USE_THOUSAND_SEPARATOR) and grouping
    1818    # Make the common case fast:
    1919    if isinstance(number, int) and not use_grouping and not decimal_pos:
    2020        return mark_safe(unicode(number))
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index cc17d74..92ad431 100644
    a b class FormattingTests(TestCase):  
    329329            self.assertEqual(u'-66666.6', nformat(-66666.666, decimal_sep='.', decimal_pos=1))
    330330            self.assertEqual(u'-66666.0', nformat(int('-66666'), decimal_sep='.', decimal_pos=1))
    331331            self.assertEqual(u'10000.0', nformat(self.l, decimal_sep='.', decimal_pos=1))
     332            # The weird grouping/force_grouping combination may be triggered by intcomma filter (#17414)
     333            self.assertEqual(u'10000', nformat(self.l, decimal_sep='.', decimal_pos=0, grouping=0, force_grouping=True))
    332334
    333335            # date filter
    334336            self.assertEqual(u'31.12.2009 в 20:50', Template('{{ dt|date:"d.m.Y в H:i" }}').render(self.ctxt))
Back to Top