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

parse_decimal is not works correctly when space symbol as grouping #637

Closed
llybin opened this issue Mar 19, 2019 · 1 comment · Fixed by #649
Closed

parse_decimal is not works correctly when space symbol as grouping #637

llybin opened this issue Mar 19, 2019 · 1 comment · Fixed by #649
Assignees

Comments

@llybin
Copy link

llybin commented Mar 19, 2019

from babel.numbers import format_decimal

format_decimal(12345.123, locale='ru')

'12\xa0345,123'
from babel.numbers import parse_decimal

parse_decimal('12 345,123', locale='ru')

babel/numbers.py", line 605, in parse_decimal
    .replace(get_decimal_symbol(locale), '.'))
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
babel.numbers.NumberFormatError

There is a problem because ' '.replace('\xa0', '.') is not replace space to dot.

akx added a commit to akx/babel that referenced this issue May 27, 2019
@akx akx self-assigned this May 27, 2019
@akx
Copy link
Member

akx commented May 27, 2019

This is technically by design, but it does make sense to allow a plain space in U+00A0's stead when it is the group separator.

@akx akx closed this as completed in #649 May 27, 2019
akx added a commit that referenced this issue May 27, 2019
ronnix added a commit to ronnix/babel that referenced this issue Jun 8, 2023
…mbers

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in python-babel#637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow any other space character (using the `\s` character class of
regular expressions) when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
ronnix added a commit to ronnix/babel that referenced this issue Nov 9, 2023
…mbers

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in python-babel#637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow any other space character (using the `\s` character class of
regular expressions) when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
ronnix added a commit to ronnix/babel that referenced this issue Apr 16, 2024
…mbers

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in python-babel#637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow any other space character (using the `\s` character class of
regular expressions) when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
ronnix added a commit to ronnix/babel that referenced this issue Apr 18, 2024
…mbers

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in python-babel#637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow any other space character (using the `\s` character class of
regular expressions) when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
akx pushed a commit that referenced this issue Apr 22, 2024
…mbers (#1007)

The French group separator is `"\u202f"` (narrow non-breaking space),
but when parsing numbers in the real world, you will most often encounter
either a regular space character (`" "`) or a non-breaking space character
(`"\xa0"`).

The issue was partially adressed earlier in #637,
but only to allow regular spaces instead of non-breaking spaces `"\xa0"` in
`parse_decimal`.

This commit goes further by changing both `parse_number` and `parse_decimal`
to allow certain other space characters when the group character is itself a space character,
but is not present in the string to parse.

Unit tests are included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants