@@ -1068,12 +1068,11 @@ def __str__(self, eng=False, context=None):
10681068 return sign + intpart + fracpart + exp
10691069
10701070 def to_eng_string (self , context = None ):
1071- """Convert to engineering-type string.
1071+ """Convert to a string, using engineering notation if an exponent is needed .
10721072
1073- Engineering notation has an exponent which is a multiple of 3, so there
1074- are up to 3 digits left of the decimal place.
1075-
1076- Same rules for when in exponential and when as a value as in __str__.
1073+ Engineering notation has an exponent which is a multiple of 3. This
1074+ can leave up to 3 digits to the left of the decimal place and may
1075+ require the addition of either one or two trailing zeros.
10771076 """
10781077 return self .__str__ (eng = True , context = context )
10791078
@@ -5502,9 +5501,29 @@ def subtract(self, a, b):
55025501 return r
55035502
55045503 def to_eng_string (self , a ):
5505- """Converts a number to a string, using scientific notation.
5504+ """Convert to a string, using engineering notation if an exponent is needed.
5505+
5506+ Engineering notation has an exponent which is a multiple of 3. This
5507+ can leave up to 3 digits to the left of the decimal place and may
5508+ require the addition of either one or two trailing zeros.
55065509
55075510 The operation is not affected by the context.
5511+
5512+ >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
5513+ '1.23E+3'
5514+ >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
5515+ '123E+3'
5516+ >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
5517+ '12.3E-9'
5518+ >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
5519+ '-123E-12'
5520+ >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
5521+ '700E-9'
5522+ >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
5523+ '70'
5524+ >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
5525+ '0.00E+3'
5526+
55085527 """
55095528 a = _convert_other (a , raiseit = True )
55105529 return a .to_eng_string (context = self )
0 commit comments