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 all commits
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
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -63,6 +63,7 @@ def run(self):
# pytz otherwise does not install on pip 1.4 or
# higher.
'pytz>=2015.7',
'freezegun==0.3.12',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a hard requirement for the library, only for the tests.

],

cmdclass={'import_cldr': import_cldr},
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'
4 changes: 2 additions & 2 deletions tox.ini
@@ -1,12 +1,12 @@
[tox]
envlist = py27, pypy, py34, py35, py36, py37, pypy3, py27-cdecimal
envlist = py27, pypy, py34, py35, py36, py37, pypy3, py27-cdecimal, py38

[testenv]
deps =
pytest==4.3.1
pytest-cov==2.6.1
cdecimal: m3-cdecimal
freezegun==0.3.11
freezegun==0.3.12
whitelist_externals = make
commands = make clean-cldr test
passenv = PYTHON_TEST_FLAGS
Expand Down