MCPcopy Index your code
hub / github.com/RustPython/RustPython / create_decimal

Method create_decimal

Lib/_pydecimal.py:4072–4087  ·  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

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

Calls 7

_raise_errorMethod · 0.95
_isnanMethod · 0.95
_fixMethod · 0.95
isinstanceFunction · 0.85
DecimalClass · 0.85
lenFunction · 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