From: He Chen Date: Mon, 19 Aug 2019 20:06:41 +0000 (-0400) Subject: fix small decimal with disabled decimal_quantization X-Git-Tag: v2.8.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df9c01c6480ef20523418079b6774612e47b8c63;p=thirdparty%2Fbabel.git fix small decimal with disabled decimal_quantization --- diff --git a/babel/numbers.py b/babel/numbers.py index 6888c9cb..cf819fc9 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -1063,7 +1063,7 @@ class NumberPattern(object): def _quantize_value(self, value, locale, frac_prec): quantum = get_decimal_quantum(frac_prec[1]) rounded = value.quantize(quantum) - a, sep, b = str(rounded).partition(".") + a, sep, b = "{:f}".format(rounded).partition(".") number = (self._format_int(a, self.int_prec[0], self.int_prec[1], locale) + self._format_frac(b or '0', locale, frac_prec)) diff --git a/tests/test_numbers.py b/tests/test_numbers.py index 6e26fe90..a980a66a 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -690,3 +690,7 @@ def test_parse_decimal_nbsp_heuristics(): n = decimal.Decimal("12345.123") assert numbers.parse_decimal("12 345.123", locale="fi") == n assert numbers.parse_decimal(numbers.format_decimal(n, locale="fi"), locale="fi") == n + + +def test_very_small_decimal_no_quantization(): + assert numbers.format_decimal(decimal.Decimal('1E-7'), locale='en', decimal_quantization=False) == '0.0000001'