[Python-checkins] cpython (merge 3.5 -> default): merge
raymond.hettinger
python-checkins at python.org
Sat Aug 13 14:16:06 EDT 2016
https://hg.python.org/cpython/rev/1b3a987d6df0
changeset: 102631:1b3a987d6df0
parent: 102628:61c4dbec2e2c
parent: 102630:de2a9c98948e
user: Raymond Hettinger <python at rcn.com>
date: Sat Aug 13 11:15:59 2016 -0700
summary:
merge
files:
Doc/library/decimal.rst | 18 ++++++++++-----
Lib/_pydecimal.py | 33 ++++++++++++++++++++++------
2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -849,11 +849,13 @@
.. method:: to_eng_string(context=None)
- Convert to an engineering-type string.
-
- Engineering notation has an exponent which is a multiple of 3, so there
- are up to 3 digits left of the decimal place. For example, converts
- ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``.
+ Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
+
+ For example, this converts ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``.
.. method:: to_integral(rounding=None, context=None)
@@ -1423,7 +1425,11 @@
.. method:: to_eng_string(x)
- Converts a number to a string, using scientific notation.
+ Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
.. method:: to_integral_exact(x)
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -1118,12 +1118,11 @@
return sign + intpart + fracpart + exp
def to_eng_string(self, context=None):
- """Convert to engineering-type string.
-
- Engineering notation has an exponent which is a multiple of 3, so there
- are up to 3 digits left of the decimal place.
-
- Same rules for when in exponential and when as a value as in __str__.
+ """Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
"""
return self.__str__(eng=True, context=context)
@@ -5552,9 +5551,29 @@
return r
def to_eng_string(self, a):
- """Converts a number to a string, using scientific notation.
+ """Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
The operation is not affected by the context.
+
+ >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
+ '1.23E+3'
+ >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
+ '123E+3'
+ >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
+ '12.3E-9'
+ >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
+ '-123E-12'
+ >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
+ '700E-9'
+ >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
+ '70'
+ >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
+ '0.00E+3'
+
"""
a = _convert_other(a, raiseit=True)
return a.to_eng_string(context=self)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list