Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Description
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