Skip to content

gh-99875: document rounding mode for old-style formatting#126382

Open
skirpichev wants to merge 2 commits intopython:mainfrom
skirpichev:format-old-rounding-99875
Open

gh-99875: document rounding mode for old-style formatting#126382
skirpichev wants to merge 2 commits intopython:mainfrom
skirpichev:format-old-rounding-99875

Conversation

@skirpichev
Copy link
Member

@skirpichev skirpichev commented Nov 4, 2024

Copy link
Contributor

@rruuaanng rruuaanng left a comment

Choose a reason for hiding this comment

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

This description looks very good : --- )

@skirpichev skirpichev removed the needs backport to 3.12 only security fixes label Apr 8, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@skirpichev
Copy link
Member Author

CC @picnixz This is follow-up off #121481

@skirpichev
Copy link
Member Author

CC @vstinner

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

Do we have tests for that? test_format.test_precision() is quite basic, it doesn't check rounding.

        f = 1.2
        self.assertEqual(format(f, ".0f"), "1")
        self.assertEqual(format(f, ".3f"), "1.200")
        with self.assertRaises(ValueError) as cm:
            format(f, ".%sf" % (sys.maxsize + 1))

@skirpichev
Copy link
Member Author

Do we have tests for that? test_format.test_precision() is quite basic, it doesn't check rounding.

We have tests in the test_float.py. E.g. test_format_testfile(). For instance:

%f 1.23456789 -> 1.234568

will fail with rounding up.

%.1f 1234.5678 -> 1234.6

will fail with rounding down. And so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants