New submission from Chris Warrick <kwpol...@gmail.com>:
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' ---------- components: Library (Lib) messages: 381578 nosy: Kwpolska priority: normal severity: normal status: open title: Behavior of general (%g, :g) formatting inconsistent for decimal.Decimal type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42429> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com