summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2010-11-25 16:08:06 +0000
committerEric Smith <eric@trueblade.com>2010-11-25 16:08:06 +0000
commit984bb58000df9cdba438c7ecb0bae5ad67878696 (patch)
tree87077ab2bbe949b5241ed9db5f2073572094ffde /Lib/decimal.py
parentc1d98d685032dd831ced32463b3f88cce6af4067 (diff)
downloadcpython-git-984bb58000df9cdba438c7ecb0bae5ad67878696.tar.gz
Issue #7094: Add alternate ('#') flag to __format__ methods for float, complex and Decimal. Allows greater control over when decimal points appear. Added to make transitioning from %-formatting easier. '#g' still has a problem with Decimal which I'll fix soon.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 5a9f840771..f379ee57ce 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -5991,7 +5991,7 @@ _exact_half = re.compile('50*$').match
#
# A format specifier for Decimal looks like:
#
-# [[fill]align][sign][0][minimumwidth][,][.precision][type]
+# [[fill]align][sign][#][0][minimumwidth][,][.precision][type]
_parse_format_specifier_regex = re.compile(r"""\A
(?:
@@ -5999,6 +5999,7 @@ _parse_format_specifier_regex = re.compile(r"""\A
(?P<align>[<>=^])
)?
(?P<sign>[-+ ])?
+(?P<alt>\#)?
(?P<zeropad>0)?
(?P<minimumwidth>(?!0)\d+)?
(?P<thousands_sep>,)?
@@ -6214,7 +6215,7 @@ def _format_number(is_negative, intpart, fracpart, exp, spec):
sign = _format_sign(is_negative, spec)
- if fracpart:
+ if fracpart or spec['alt']:
fracpart = spec['decimal_point'] + fracpart
if exp != 0 or spec['type'] in 'eE':