Mercurial > babel > mirror
changeset 576:e77dd06c40ef trunk
fix formatting of fraction in format_decimal() if the input value is a float with more than 7 significant digits (#183)
author | fschwarz |
---|---|
date | Sat, 28 Jul 2012 22:26:02 +0000 |
parents | 8ce41e60f90d |
children | e57abed6542a |
files | ChangeLog babel/numbers.py babel/tests/numbers.py |
diffstat | 3 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,8 @@ * 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/
--- a/babel/numbers.py +++ b/babel/numbers.py @@ -478,6 +478,8 @@ 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
--- a/babel/tests/numbers.py +++ b/babel/tests/numbers.py @@ -28,6 +28,12 @@ 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.##;-#',