Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions babel/plural.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ def extract_operands(
if isinstance(n, decimal.Decimal):
dec_tuple = n.as_tuple()
exp = dec_tuple.exponent
fraction_digits = dec_tuple.digits[exp:] if exp < 0 else ()
trailing = ''.join(str(d) for d in fraction_digits)
if exp < 0:
fraction_digits = dec_tuple.digits[exp:]
leading_zeros = -exp - len(fraction_digits)
trailing = '0' * leading_zeros + ''.join(str(d) for d in fraction_digits)
else:
trailing = ''
no_trailing = trailing.rstrip('0')
v = len(trailing)
w = len(no_trailing)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_plural.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def test_next_token_type_not_ok_and_value_ok():
(decimal.Decimal('1.230'), '1.230', 1, 3, 2, 230, 23),
(-1, 1, 1, 0, 0, 0, 0),
(1.3, '1.3', 1, 1, 1, 3, 3),
(decimal.Decimal('0.05'), '0.05', 0, 2, 2, 5, 5),
(0.005, '0.005', 0, 3, 3, 5, 5),
(decimal.Decimal('0.00'), '0.00', 0, 2, 0, 0, 0),
(decimal.Decimal('0.0050'), '0.0050', 0, 4, 3, 50, 5),
)


Expand Down