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 floats#125304
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5858d8cd7b37845b70fff42df636ca70d8928b91370a0b3b059aab3c02d44de4d32cd5e359616ea851c34d3f0e3c008a6e1c36219893421dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -754,6 +754,28 @@ def test_format(self): | ||
| self.assertEqual(format(INF, 'f'), 'inf') | ||
| self.assertEqual(format(INF, 'F'), 'INF') | ||
| # thousands separators | ||
| x = 123_456.123_456 | ||
| self.assertEqual(format(x, '_f'), '123_456.123456') | ||
| self.assertEqual(format(x, ',f'), '123,456.123456') | ||
| self.assertEqual(format(x, '._f'), '123456.123_456') | ||
| self.assertEqual(format(x, '.,f'), '123456.123,456') | ||
| self.assertEqual(format(x, '_._f'), '123_456.123_456') | ||
| self.assertEqual(format(x, ',.,f'), '123,456.123,456') | ||
| self.assertEqual(format(x, '.10_f'), '123456.123_456_000_0') | ||
| self.assertEqual(format(x, '.10,f'), '123456.123,456,000,0') | ||
| self.assertEqual(format(x, '>21._f'), ' 123456.123_456') | ||
| self.assertEqual(format(x, '<21._f'), '123456.123_456 ') | ||
skirpichev marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| self.assertEqual(format(x, '+.11_e'), '+1.234_561_234_56e+05') | ||
| self.assertEqual(format(x, '+.11,e'), '+1.234,561,234,56e+05') | ||
| self.assertRaises(ValueError, format, x, '._6f') | ||
| self.assertRaises(ValueError, format, x, '.,_f') | ||
| self.assertRaises(ValueError, format, x, '.6,_f') | ||
| self.assertRaises(ValueError, format, x, '.6_,f') | ||
| self.assertRaises(ValueError, format, x, '.6_n') | ||
| self.assertRaises(ValueError, format, x, '.6,n') | ||
| @support.requires_IEEE_754 | ||
| def test_format_testfile(self): | ||
| with open(format_testfile, encoding="utf-8") as testfile: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Support underscore and comma as thousands separators in the fractional part for | ||
| floating-point presentation types of the new-style string formatting (with | ||
| :func:`format` or :ref:`f-strings`). Patch by Sergey B Kirpichev. | ||
skirpichev marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.