Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17414 -- Prevented numberformat from trying to group digits wh…

…en the number of digits per group is zero.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17267 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ddb2a9eb9e3f3f14212eb85325fb2f30aba1fb1f 1 parent 1c16907
Aymeric Augustin authored December 24, 2011
6  django/contrib/humanize/tests.py
@@ -53,6 +53,12 @@ def test_l10n_intcomma(self):
53 53
         with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):
54 54
             self.humanize_tester(test_list, result_list, 'intcomma')
55 55
 
  56
+    def test_intcomma_without_number_grouping(self):
  57
+        # Regression for #17414
  58
+        with translation.override('ja'):
  59
+            with self.settings(USE_L10N=True):
  60
+                self.humanize_tester([100], ['100'], 'intcomma')
  61
+
56 62
     def test_intword(self):
57 63
         test_list = ('100', '1000000', '1200000', '1290000',
58 64
                      '1000000000', '2000000000', '6000000000000',
16  django/utils/numberformat.py
@@ -2,20 +2,21 @@
2 2
 from django.utils.safestring import mark_safe
3 3
 
4 4
 
5  
-def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', force_grouping=False):
  5
+def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='',
  6
+           force_grouping=False):
6 7
     """
7 8
     Gets a number (as a number or string), and returns it as a string,
8  
-    using formats definied as arguments:
  9
+    using formats defined as arguments:
9 10
 
10 11
     * decimal_sep: Decimal separator symbol (for example ".")
11 12
     * decimal_pos: Number of decimal positions
12 13
     * grouping: Number of digits in every group limited by thousand separator
13 14
     * thousand_sep: Thousand separator symbol (for example ",")
14  
-
15 15
     """
16  
-    use_grouping = force_grouping or settings.USE_L10N and \
17  
-        settings.USE_THOUSAND_SEPARATOR and grouping
18  
-    # Make the common case fast:
  16
+    use_grouping = settings.USE_L10N and settings.USE_THOUSAND_SEPARATOR
  17
+    use_grouping = use_grouping or force_grouping
  18
+    use_grouping = use_grouping and grouping > 0
  19
+    # Make the common case fast
19 20
     if isinstance(number, int) and not use_grouping and not decimal_pos:
20 21
         return mark_safe(unicode(number))
21 22
     # sign
@@ -35,7 +36,8 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', f
35 36
         int_part, dec_part = str_number, ''
36 37
     if decimal_pos is not None:
37 38
         dec_part = dec_part + ('0' * (decimal_pos - len(dec_part)))
38  
-    if dec_part: dec_part = decimal_sep + dec_part
  39
+    if dec_part:
  40
+        dec_part = decimal_sep + dec_part
39 41
     # grouping
40 42
     if use_grouping:
41 43
         int_part_gd = ''

0 notes on commit ddb2a9e

Please sign in to comment.
Something went wrong with that request. Please try again.