[issue40780] str.format() handles trailing zeros inconsistently in “general” format

Eric V. Smith report at bugs.python.org
Tue May 26 11:12:32 EDT 2020


Eric V. Smith <eric at trueblade.com> added the comment:

FWIW, which is probably not much with ".g" formatting, this is how Decimal behaves:

>>> from decimal import Decimal as D
>>> format(D(1504), '.3g')
'1.50e+3'
>>> format(D(1505), '.3g')
'1.50e+3'
>>> format(D(1506), '.3g')
'1.51e+3'
>>> format(D(1504.0), '.3g')
'1.50e+3'
>>> format(D(1505.0), '.3g')
'1.50e+3'
>>> format(D(1506.0), '.3g')
'1.51e+3'
>>> format(D("1504.0"), '.3g')
'1.50e+3'
>>> format(D("1505.0"), '.3g')
'1.50e+3'
>>> format(D("1506.0"), '.3g')
'1.51e+3'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40780>
_______________________________________


More information about the Python-bugs-list mailing list