[New-bugs-announce] [issue45708] PEP 515-style formatting with underscores does not seem to work for Decimal
Sander Bollen
report at bugs.python.org
Thu Nov 4 05:01:14 EDT 2021
New submission from Sander Bollen <sander at sndrtj.eu>:
Hello,
It appears that Decimal does not support PEP-515 style formatting with underscores as thousands separators.
```
>>> from decimal import Decimal
>>> f"{Decimal('5000'):,}"
'5,000'
>>> f"{Decimal('5000'):_}"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid format string
```
This does work for all the other types mentioned in PEP515
```
>>> f"{5000:_}"
'5_000'
>>> f"{5000.0:_}"
'5_000.0'
>>> f"{complex(5000, 1):_}"
'(5_000+1j)'
```
I have tried this on python 3.8, 3.9 and 3.10 on a Mac.
----------
components: Library (Lib)
messages: 405667
nosy: sndrtj
priority: normal
severity: normal
status: open
title: PEP 515-style formatting with underscores does not seem to work for Decimal
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45708>
_______________________________________
More information about the New-bugs-announce
mailing list