]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
fix small decimal with disabled decimal_quantization
authorHe Chen <hchen584@bloomberg.net>
Mon, 19 Aug 2019 20:06:41 +0000 (16:06 -0400)
committerAarni Koskela <akx@iki.fi>
Tue, 31 Dec 2019 09:47:59 +0000 (11:47 +0200)
babel/numbers.py
tests/test_numbers.py

index 6888c9cb47595e16b37e4cbdec3b297db3f0726e..cf819fc9a1e654a70e2d354d93da6d69837936cd 100644 (file)
@@ -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))
index 6e26fe90011753f6adc7e430c456dc9252a001a6..a980a66ad380c8b69a90b8b3188a66911d1678f4 100644 (file)
@@ -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'