Skip to content

Commit

Permalink
Fixed parse_number()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebas-inf committed Jan 31, 2024
1 parent 40e60a1 commit 2e0a5a3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,8 @@ def parse_number(
1099
>>> parse_number('1.099', locale='de_DE')
1099
>>> parse_number('1 099', locale='ru')
1099
When the given string cannot be parsed, an exception is raised:
Expand All @@ -1027,11 +1029,21 @@ def parse_number(
:raise `UnsupportedNumberingSystemError`: if the numbering system is not supported by the locale.
"""
try:
return int(string.replace(get_group_symbol(locale, numbering_system=numbering_system), ''))
# Get the group symbol from the locale
group_symbol = get_group_symbol(locale, numbering_system=numbering_system)

# Replace non-breakable spaces with the group symbol
cleaned_string = string.replace('\xa0', group_symbol)

# Remove other spaces and replace the group symbol with an empty string
cleaned_string = cleaned_string.replace(' ', '').replace(group_symbol, '')

return int(cleaned_string)
except ValueError as ve:
raise NumberFormatError(f"{string!r} is not a valid number") from ve



def parse_decimal(
string: str,
locale: Locale | str | None = LC_NUMERIC,
Expand Down

0 comments on commit 2e0a5a3

Please sign in to comment.