You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
, works with Decimal() against the doc of **Format Specification Mini-Language** #136636
The doc of Format Specification Mini-Language doesn't say that , works with Decimal() as shown below:
',': Inserts a comma every 3 digits for integer presentation type 'd' and floating-point presentation types, excluding 'n'. For other presentation types, this option is not supported.
But , works with Decimal() against the doc as shown below:
In addition, the doc doesn't say that _ works with Decimal() as shown below:
'_': Inserts an underscore every 3 digits for integer presentation type 'd' and floating-point presentation types, excluding 'n'. For integer presentation types 'b', 'o', 'x', and 'X', underscores are inserted every 4 digits. For other presentation types, this option is not supported.
So, _ doesn't work with Decimal() as the doc doesn't say so as shown below:
fromdecimalimportDecimalv=Decimal(value='1234.5555555555')
print('"{:_.20f}"'.format(v))
print('"{:_.20F}"'.format(v))
print('"{:_f}"'.format(v))
print('"{:_F}"'.format(v))
# ValueError: invalid format string
I'm not sure I understand the first issue namely with ,. The grammar says:
grouping ::= "," | "_"
So , is supported as you observed (both for integer and floating-point presentations). As for _, do you mean that it doesn't work for any of the floating-point presentation types? I don't have access to a 3.13+ installation so I can't check. Also, in the future, please check the bugs against the stable versions, and not those that are security-only.
This is certainly not a bug. The Decimal formatting is documented on the quoted page, as it says that available presentation types for floats and Decimals are same.
On the other hand, the Decimal is not a builtin type, maybe it's better to document it's formatting separately, as for Fractions, in the module page. (Right now it even has no examples of formatted output, see #128698.)
The "floating-point presentation types" are the implicit or explict f,F,g,G, not the object type. I don't see why you are getting the error messages. Maybe a fixed bug. In installed 3.14.0b4 and main:
Activity
picnixz commentedon Jul 13, 2025
I'm not sure I understand the first issue namely with
,. The grammar says:So
,is supported as you observed (both for integer and floating-point presentations). As for_, do you mean that it doesn't work for any of the floating-point presentation types? I don't have access to a 3.13+ installation so I can't check. Also, in the future, please check the bugs against the stable versions, and not those that are security-only.cc @skirpichev
skirpichev commentedon Jul 14, 2025
This is certainly not a bug. The Decimal formatting is documented on the quoted page, as it says that available presentation types for floats and Decimals are same.
On the other hand, the Decimal is not a builtin type, maybe it's better to document it's formatting separately, as for Fractions, in the module page. (Right now it even has no examples of formatted output, see #128698.)
terryjreedy commentedon Jul 14, 2025
The "floating-point presentation types" are the implicit or explict f,F,g,G, not the object type. I don't see why you are getting the error messages. Maybe a fixed bug. In installed 3.14.0b4 and main:
Same with f-strings.
EDIT: Mismatches between presentation type and object type are ValueErrors.
skirpichev commentedon Jul 14, 2025
Ah, I thought my patch was backported: #132155
skirpichev commentedon Jul 14, 2025
Backport for 3.13: #136649
3.12 is security-only, so we can't do anything here.
StanFromIreland commentedon Jul 14, 2025
Backport has been merged, should this not be classified as a duplicate of its issue?
picnixz commentedon Jul 14, 2025
Yes, it would be a duplicate now.