]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
fix formatting of fraction in format_decimal() if the input value is a float with...
authorFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Sat, 28 Jul 2012 22:26:02 +0000 (22:26 +0000)
committerFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Sat, 28 Jul 2012 22:26:02 +0000 (22:26 +0000)
ChangeLog
babel/numbers.py
babel/tests/numbers.py

index 05e1127b890c8319c46e235672f1839fd68f7930..14722b2d3cde0be0419d6febfa4fe71f0ce5d331 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -39,6 +39,8 @@ http://svn.edgewall.org/repos/babel/tags/1.0.0/
  * Support for context-aware methods during message extraction (#229, patch
    from David Rios)
  * "init" and "update" commands support "--no-wrap" option (#289)
+ * fix formatting of fraction in format_decimal() if the input value is a float
+   with more than 7 significant digits (#183)
 
 Version 0.9.6
 http://svn.edgewall.org/repos/babel/tags/0.9.6/
index 632dd6409f2ce93b0b6673c6df94df625c0eacf3..795a0fa25d9a5533b5902dc417fe8537babe97ff 100644 (file)
@@ -478,6 +478,8 @@ class NumberPattern(object):
         return '<%s %r>' % (type(self).__name__, self.pattern)
 
     def apply(self, value, locale, currency=None):
+        if isinstance(value, float):
+            value = Decimal(str(value))
         value *= self.scale
         is_negative = int(value < 0)
         if self.exp_prec: # Scientific notation
index f4d1d4e34b69ec39c90d390240b498a5d26df5cd..caaa1d08b9c8baa61e989cec19ed5b4a0c39aac8 100644 (file)
@@ -28,6 +28,12 @@ class FormatDecimalTestCase(unittest.TestCase):
         self.assertEqual(numbers.format_decimal(10.0**20, 
                                                 '#.00', locale='en_US'), 
                          '100000000000000000000.00')
+        # regression test for #183, fraction digits were not correctly cutted
+        # if the input was a float value and the value had more than 7 
+        # significant digits
+        self.assertEqual(u'12,345,678.05',
+                         numbers.format_decimal(12345678.051, '#,##0.00', 
+                         locale='en_US'))
 
     def test_subpatterns(self):
         self.assertEqual(numbers.format_decimal(-12345, '#,##0.##;-#',