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(numbers): correctly determine malformed decimals #1042

Merged
merged 3 commits into from Nov 28, 2023

Conversation

Olunusib
Copy link
Contributor

Fixes #928

Problem:

The current code was primarily designed for numbers like 3,400.00, where the r-stripped value (3,400.) matches the expected proper (3,400) + . (3,400.) format. It doesn't work for numbers like 3,400.60 since 3,400.6 (the value after r-stripping) is incorrectly perceived as not equal to the expected format, which is the proper (3,400.6) + . (3,400.6.), thereby leading to its erroneous detection as improperly formatted.

Solution:

Added a more robust method for stripping trailing zeros, specifically targeting only those zeros that appear after the last non-zero digit following the decimal symbol.

Copy link

codecov bot commented Nov 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (aca7663) 91.43% compared to head (e89a6c9) 91.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1042      +/-   ##
==========================================
+ Coverage   91.43%   91.44%   +0.01%     
==========================================
  Files          26       26              
  Lines        4436     4444       +8     
==========================================
+ Hits         4056     4064       +8     
  Misses        380      380              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

babel/util.py Outdated Show resolved Hide resolved
babel/util.py Outdated Show resolved Hide resolved
@Olunusib Olunusib force-pushed the fix/parse-decimal-trailing-zeros branch 2 times, most recently from 1e42514 to 725bb57 Compare November 23, 2023 18:47
Signed-off-by: Olunusi Best <olunusibest@gmail.com>
@akx akx force-pushed the fix/parse-decimal-trailing-zeros branch from 725bb57 to 8f39f58 Compare November 28, 2023 09:34
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

Thank you! I took the liberty of rebasing this, cleaning up the logic a bit and adding a few more test cases for good measure.

@akx akx enabled auto-merge (squash) November 28, 2023 09:42
@akx akx merged commit 946efcd into python-babel:master Nov 28, 2023
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parse_decimal raises error for decimals with thousand separator and trailing zeroes
2 participants