Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-87790: support thousands separators for formatting fractional part of Decimal#132202
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
9cac451 gh-87790: support thousands separators for formatting fractional part…
skirpichev 40e1647 Merge branch 'master' into frac-sep-Decimal/87790
skirpichev 164bdf8 Merge branch 'main' into frac-sep-Decimal/87790
skirpichev 387090a Update Lib/_pydecimal.py
skirpichev 02f0b3d Merge branch 'master' into frac-sep-Decimal/87790
skirpichev 51592d4 address review: test error for _6f
skirpichev 0353e99 address review: fix .6_f test (enlarge integer part)
skirpichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1089,6 +1089,15 @@ def test_formatting(self): | ||
| ('07_', '1234.56', '1_234.56'), | ||
| ('_', '1.23456789', '1.23456789'), | ||
| ('_%', '123.456789', '12_345.6789%'), | ||
| # and now for something completely different... | ||
| ('.,', '1.23456789', '1.234,567,89'), | ||
| ('._', '1.23456789', '1.234_567_89'), | ||
| ('.6_f', '12345.23456789', '12345.234_568'), | ||
| (',._%', '123.456789', '12,345.678_9%'), | ||
| (',._e', '123456', '1.234_56e+5'), | ||
| (',.4_e', '123456', '1.234_6e+5'), | ||
| (',.3_e', '123456', '1.235e+5'), | ||
| (',._E', '123456', '1.234_56E+5'), | ||
| # negative zero: default behavior | ||
| ('.1f', '-0', '-0.0'), | ||
| @@ -1162,6 +1171,10 @@ def test_formatting(self): | ||
| # bytes format argument | ||
| self.assertRaises(TypeError, Decimal(1).__format__, b'-020') | ||
| # precision or fractional part separator should follow after dot | ||
| self.assertRaises(ValueError, format, Decimal(1), '.f') | ||
skirpichev marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| self.assertRaises(ValueError, format, Decimal(1), '._6f') | ||
| def test_negative_zero_format_directed_rounding(self): | ||
| with self.decimal.localcontext() as ctx: | ||
| ctx.rounding = ROUND_CEILING | ||
2 changes: 2 additions & 0 deletions 2 Misc/NEWS.d/next/Library/2025-04-07-09-53-54.gh-issue-87790.6nj3zQ.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Support underscore and comma as thousands separators in the fractional part | ||
| for :class:`~decimal.Decimal`'s formatting. Patch by Sergey B Kirpichev. |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.