This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author MonsieurPaul
Recipients MonsieurPaul
Date 2015-03-27.13:01:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427461273.99.0.604875598845.issue23789@psf.upfronthosting.co.za>
In-reply-to
Content
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 += '%'
History
Date User Action Args
2015-03-27 13:01:14MonsieurPaulsetrecipients: + MonsieurPaul
2015-03-27 13:01:13MonsieurPaulsetmessageid: <1427461273.99.0.604875598845.issue23789@psf.upfronthosting.co.za>
2015-03-27 13:01:13MonsieurPaullinkissue23789 messages
2015-03-27 13:01:13MonsieurPaulcreate