Skip to content

Commit

Permalink
fix small decimal with disabled decimal_quantization
Browse files Browse the repository at this point in the history
  • Loading branch information
He Chen authored and akx committed Dec 31, 2019
1 parent 30355ca commit df9c01c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion babel/numbers.py
Expand Up @@ -1063,7 +1063,7 @@ def _format_int(self, value, min, max, locale):
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))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_numbers.py
Expand Up @@ -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'

0 comments on commit df9c01c

Please sign in to comment.