Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed as duplicate of#130664
Labels
3.13bugs and security fixesextension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@hyperkai

Description

@hyperkai

Bug report

Bug description:

The doc ofFormat Specification Mini-Language doesn't say that, works withDecimal() 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 withDecimal() 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 withDecimal() 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 withDecimal() 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 dirstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp