@@ -1118,12 +1118,11 @@ def __str__(self, eng=False, context=None):
11181118 return sign + intpart + fracpart + exp
11191119
11201120 def to_eng_string (self , context = None ):
1121- """Convert to engineering-type string.
1121+ """Convert to a string, using engineering notation if an exponent is needed .
11221122
1123- Engineering notation has an exponent which is a multiple of 3, so there
1124- are up to 3 digits left of the decimal place.
1125-
1126- Same rules for when in exponential and when as a value as in __str__.
1123+ Engineering notation has an exponent which is a multiple of 3. This
1124+ can leave up to 3 digits to the left of the decimal place and may
1125+ require the addition of either one or two trailing zeros.
11271126 """
11281127 return self .__str__ (eng = True , context = context )
11291128
@@ -5552,9 +5551,29 @@ def subtract(self, a, b):
55525551 return r
55535552
55545553 def to_eng_string (self , a ):
5555- """Converts a number to a string, using scientific notation.
5554+ """Convert to a string, using engineering notation if an exponent is needed.
5555+
5556+ Engineering notation has an exponent which is a multiple of 3. This
5557+ can leave up to 3 digits to the left of the decimal place and may
5558+ require the addition of either one or two trailing zeros.
55565559
55575560 The operation is not affected by the context.
5561+
5562+ >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
5563+ '1.23E+3'
5564+ >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
5565+ '123E+3'
5566+ >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
5567+ '12.3E-9'
5568+ >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
5569+ '-123E-12'
5570+ >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
5571+ '700E-9'
5572+ >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
5573+ '70'
5574+ >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
5575+ '0.00E+3'
5576+
55585577 """
55595578 a = _convert_other (a , raiseit = True )
55605579 return a .to_eng_string (context = self )
0 commit comments