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

Method create_decimal

Lib/_pydecimal.py:4075–4090  ·  view source on GitHub ↗

Creates a new Decimal instance but using self as context. This method implements the to-number operation of the IBM Decimal specification.

(self, num='0')

Source from the content-addressed store, hash-verified

4073 return rounding
4074
4075 def create_decimal(self, num='0'):
4076 """Creates a new Decimal instance but using self as context.
4077
4078 This method implements the to-number operation of the
4079 IBM Decimal specification."""
4080
4081 if isinstance(num, str) and (num != num.strip() or '_' in num):
4082 return self._raise_error(ConversionSyntax,
4083 "trailing or leading whitespace and "
4084 "underscores are not permitted.")
4085
4086 d = Decimal(num, context=self)
4087 if d._isnan() and len(d._int) > self.prec - self.clamp:
4088 return self._raise_error(ConversionSyntax,
4089 "diagnostic info too long in NaN")
4090 return d._fix(self)
4091
4092 def create_decimal_from_float(self, f):
4093 """Creates a new Decimal instance from a float but rounding using self

Callers 8

read_unlimitedMethod · 0.80
eval_equationMethod · 0.80
test_float_operationMethod · 0.80
test_from_tupleMethod · 0.80
RestrictedDecimalFunction · 0.80

Calls 5

_raise_errorMethod · 0.95
_isnanMethod · 0.95
_fixMethod · 0.95
DecimalClass · 0.85
stripMethod · 0.45

Tested by 7

read_unlimitedMethod · 0.64
eval_equationMethod · 0.64
test_float_operationMethod · 0.64
test_from_tupleMethod · 0.64