Skip to content

, works with Decimal() against the doc of **Format Specification Mini-Language** #136636

Description

@hyperkai

Bug report

Bug description:

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:

fromdecimalimportDecimalv=Decimal(value='1234.5555555555')
print('"{:,.20f}"'.format(v))
print('"{:,.20F}"'.format(v))
# "1,234.55555555550000000000"# | 20 |print('"{:,f}"'.format(v))
print('"{:,F}"'.format(v))
# "1,234.5555555555"# | 10 |
fromdecimalimportDecimalv=Decimal('123456.78912')
print('"{:,.20g}"'.format(v))
print('"{:,.20G}"'.format(v))
print('"{:,.20}"'.format(v))
print('"{:,g}"'.format(v))
print('"{:,G}"'.format(v))
print('"{:,}"'.format(v))
# "123,456.78912"# | 11 |

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
fromdecimalimportDecimalv=Decimal('123456.78912')
print('"{:_.20g}"'.format(v))
print('"{:_.20G}"'.format(v))
print('"{:_.20}"'.format(v))
print('"{:_g}"'.format(v))
print('"{:_G}"'.format(v))
print('"{:_}"'.format(v))
# ValueError: invalid format string

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesextension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions