Message381578
When formatting decimal.Decimal using old-style formatting (%g), the output is as short as possible, as expected. When using new-style formatting (str.format or f-strings), the output uses the input precision. Floats behave correctly with new-style formatting.
Python 3.9.0 (default, Oct 27 2020, 14:15:17)
[Clang 12.0.0 (clang-1200.0.32.21)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> d1 = decimal.Decimal("1.000")
>>> d2 = decimal.Decimal("1.500")
>>> f1 = 1.0
>>> f2 = 1.5
>>> f"{d1:g} {f1:g}"
'1.000 1'
>>> f"{d2:g} {f2:g}"
'1.500 1.5'
>>> "%g %g" % (d1, f1)
'1 1'
>>> "%g %g" % (d2, f2)
'1.5 1.5' |
|
Date |
User |
Action |
Args |
2020-11-21 23:29:41 | Kwpolska | set | recipients:
+ Kwpolska |
2020-11-21 23:29:40 | Kwpolska | set | messageid: <1606001380.98.0.451619022303.issue42429@roundup.psfhosted.org> |
2020-11-21 23:29:40 | Kwpolska | link | issue42429 messages |
2020-11-21 23:29:40 | Kwpolska | create | |
|