Repository navigation
Undocumented handling of thousands separator for floats and differences wrt Decimal #130664
Copy link
Copy link
Open
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dirextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Feb 28, 2025 - removedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Apr 6, 2025 There is also a wart: specifying the thousands separator with zero padding can increase the length of the resulting string over the specified width:
>>> format(1, '04') '0001' >>> format(1, '04,') '0,001' >>> format(1, '4,') ' 1'
- added a commit that references this issue
on Jul 3, 2025 specifying the thousands separator with zero padding can increase the length of the resulting string over the specified width
@serhiy-storchaka, I think we shouldn't add anything (after #131030). Docs says:
The width is a decimal integer defining the minimum total field width, including any prefixes, separators, and other formatting characters.
IMO, it's obvious, that as separators are placed between zeros (i.e. we can't start with
'_'or',') - the output string can be bigger from that.So, #131030 should finally fix issue.
- added a commit that references this issue
on Jul 14, 2025 - marked
,works withDecimal()against the doc of **Format Specification Mini-Language** #136636 as a duplicate of this issueon Jul 14, 2025
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsTodo
Bug report
Bug description:
In docs we have:
But this doesn't specify how separators are inserted for customized alignment, consider:
Probably it's obvious, that separators might be inserted only in case of 0-padding and
=alignment, though maybe this should be mentioned explicitly.Note also that neither from above supported by Decimal/Fraction, e.g.:
BTW, the rationale for Fraction's behavior (see #100161) is "no special-casing of the particular '0=' fill-character/alignment combination", which is rather weak, IMO.
Either this should be fixed (preferred) or documented.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs