New submission from Paul Eckhardt: The bahaviour of __format__ for decimal.Decimal type differs in one detail from float: The minimum number of digits used for the exponent is 1 for Decimal, and 2 for float. e.g.: "{:8.2E}".format(1.0) --> "1.00E+00" "{:8.2E}".format(Decimal(1.0)) --> " 1.00E+0"
Is there any reason for this? If not, the following patch should do: --- /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py 2015-03-27 12:55:22.000000000 +0100 +++ ./decimal.py 2015-03-27 14:00:09.000000000 +0100 @@ -6116,7 +6116,7 @@ if exp != 0 or spec['type'] in 'eE': echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']] - fracpart += "{0}{1:+}".format(echar, exp) + fracpart += "{0}{1:+03d}".format(echar, exp) if spec['type'] == '%': fracpart += '%' ---------- components: Library (Lib) messages: 239394 nosy: MonsieurPaul priority: normal severity: normal status: open title: decimal.Decimal: __format__ behaviour type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23789> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com