MCPcopy Index your code
hub / github.com/python/cpython / to_eng_string

Method to_eng_string

Lib/_pydecimal.py:5497–5523  ·  view source on GitHub ↗

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.

(self, a)

Source from the content-addressed store, hash-verified

5495 return r
5496
5497 def to_eng_string(self, a):
5498 """Convert to a string, using engineering notation if an exponent is needed.
5499
5500 Engineering notation has an exponent which is a multiple of 3. This
5501 can leave up to 3 digits to the left of the decimal place and may
5502 require the addition of either one or two trailing zeros.
5503
5504 The operation is not affected by the context.
5505
5506 >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
5507 '1.23E+3'
5508 >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
5509 '123E+3'
5510 >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
5511 '12.3E-9'
5512 >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
5513 '-123E-12'
5514 >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
5515 '700E-9'
5516 >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
5517 '70'
5518 >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
5519 '0.00E+3'
5520
5521 """
5522 a = _convert_other(a, raiseit=True)
5523 return a.to_eng_string(context=self)
5524
5525 def to_sci_string(self, a):
5526 """Converts a number to a string, using scientific notation.

Callers 1

test_to_eng_stringMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
to_eng_stringMethod · 0.45

Tested by 1

test_to_eng_stringMethod · 0.76