Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix small decimal with disabled decimal_quantization #662

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'