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

Add negative sign after currency names (#937) #938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def _match_number(pattern):
neg_prefix, _, neg_suffix = _match_number(neg_pattern)
else:
pos_prefix, number, pos_suffix = _match_number(pos_pattern)
neg_prefix = f"-{pos_prefix}"
neg_prefix = f"-{pos_prefix}" if '¤' not in pattern else f'{pos_prefix}-'
neg_suffix = pos_suffix
if 'E' in number:
number, exp = number.split('E', 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def test_format_compact_currency():
assert numbers.format_compact_currency(999, 'USD', locale='en_US', format_type="short") == u'$999'
assert numbers.format_compact_currency(123456789, 'USD', locale='en_US', format_type="short") == u'$123M'
assert numbers.format_compact_currency(123456789, 'USD', locale='en_US', fraction_digits=2, format_type="short") == u'$123.46M'
assert numbers.format_compact_currency(-123456789, 'USD', locale='en_US', fraction_digits=2, format_type="short") == u'-$123.46M'
assert numbers.format_compact_currency(-123456789, 'USD', locale='en_US', fraction_digits=2, format_type="short") == u'$-123.46M'
assert numbers.format_compact_currency(1, 'JPY', locale='ja_JP', format_type="short") == u'¥1'
assert numbers.format_compact_currency(1234, 'JPY', locale='ja_JP', format_type="short") == u'¥1234'
assert numbers.format_compact_currency(123456, 'JPY', locale='ja_JP', format_type="short") == u'¥12万'
Expand Down Expand Up @@ -675,7 +675,7 @@ def test_parse_pattern_negative():

# No negative format specified
np = numbers.parse_pattern(u'¤#,##0.00')
assert np.prefix == (u'¤', u'')
assert np.prefix == (u'¤', u'¤-')
assert np.suffix == (u'', u'')

# Negative format is specified
Expand Down