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

Method normalize

Lib/_pydecimal.py:5031–5053  ·  view source on GitHub ↗

normalize reduces an operand to its simplest form. Essentially a plus operation with all trailing zeros removed from the result. >>> ExtendedContext.normalize(Decimal('2.1')) Decimal('2.1') >>> ExtendedContext.normalize(Decimal('-2.0')) Decimal('-2')

(self, a)

Source from the content-addressed store, hash-verified

5029 return a.next_toward(b, context=self)
5030
5031 def normalize(self, a):
5032 """normalize reduces an operand to its simplest form.
5033
5034 Essentially a plus operation with all trailing zeros removed from the
5035 result.
5036
5037 >>> ExtendedContext.normalize(Decimal('2.1'))
5038 Decimal('2.1')
5039 >>> ExtendedContext.normalize(Decimal('-2.0'))
5040 Decimal('-2')
5041 >>> ExtendedContext.normalize(Decimal('1.200'))
5042 Decimal('1.2')
5043 >>> ExtendedContext.normalize(Decimal('-120'))
5044 Decimal('-1.2E+2')
5045 >>> ExtendedContext.normalize(Decimal('120.00'))
5046 Decimal('1.2E+2')
5047 >>> ExtendedContext.normalize(Decimal('0.00'))
5048 Decimal('0')
5049 >>> ExtendedContext.normalize(6)
5050 Decimal('6')
5051 """
5052 a = _convert_other(a, raiseit=True)
5053 return a.normalize(context=self)
5054
5055 def number_class(self, a):
5056 """Returns an indication of the class of the operand.

Callers 1

test_normalizeMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
normalizeMethod · 0.45

Tested by 1

test_normalizeMethod · 0.76