Author: jezdez
Date: 2011-04-22 05:03:10 -0700 (Fri, 22 Apr 2011)
New Revision: 16074

Modified:
   django/trunk/django/utils/numberformat.py
   django/trunk/tests/regressiontests/i18n/tests.py
Log:
Fixed #13810 -- Truncate numbers correctly when given number of decimal 
positions is zero. Thanks, milosu  and ?\197?\129ukasz Rekucki.

Modified: django/trunk/django/utils/numberformat.py
===================================================================
--- django/trunk/django/utils/numberformat.py   2011-04-22 12:03:03 UTC (rev 
16073)
+++ django/trunk/django/utils/numberformat.py   2011-04-22 12:03:10 UTC (rev 
16074)
@@ -2,7 +2,7 @@
 from django.utils.safestring import mark_safe
 
 
-def format(number, decimal_sep, decimal_pos, grouping=0, thousand_sep=''):
+def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''):
     """
     Gets a number (as a number or string), and returns it as a string,
     using formats definied as arguments:
@@ -29,11 +29,11 @@
     # decimal part
     if '.' in str_number:
         int_part, dec_part = str_number.split('.')
-        if decimal_pos:
+        if decimal_pos is not None:
             dec_part = dec_part[:decimal_pos]
     else:
         int_part, dec_part = str_number, ''
-    if decimal_pos:
+    if decimal_pos is not None:
         dec_part = dec_part + ('0' * (decimal_pos - len(dec_part)))
     if dec_part: dec_part = decimal_sep + dec_part
     # grouping

Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py    2011-04-22 12:03:03 UTC 
(rev 16073)
+++ django/trunk/tests/regressiontests/i18n/tests.py    2011-04-22 12:03:10 UTC 
(rev 16074)
@@ -171,6 +171,7 @@
         settings.USE_THOUSAND_SEPARATOR = False
         self.assertEqual(u'66666.66', nformat(self.n, decimal_sep='.', 
decimal_pos=2, grouping=3, thousand_sep=','))
         self.assertEqual(u'66666A6', nformat(self.n, decimal_sep='A', 
decimal_pos=1, grouping=1, thousand_sep='B'))
+        self.assertEqual(u'66666', nformat(self.n, decimal_sep='X', 
decimal_pos=0, grouping=1, thousand_sep='Y'))
 
         settings.USE_THOUSAND_SEPARATOR = True
         self.assertEqual(u'66,666.66', nformat(self.n, decimal_sep='.', 
decimal_pos=2, grouping=3, thousand_sep=','))

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to