MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / from_decimal

Method from_decimal

tools/python-3.11.9-amd64/Lib/fractions.py:183–192  ·  view source on GitHub ↗

Converts a finite Decimal instance to a rational number, exactly.

(cls, dec)

Source from the content-addressed store, hash-verified

181
182 @classmethod
183 def from_decimal(cls, dec):
184 """Converts a finite Decimal instance to a rational number, exactly."""
185 from decimal import Decimal
186 if isinstance(dec, numbers.Integral):
187 dec = Decimal(int(dec))
188 elif not isinstance(dec, Decimal):
189 raise TypeError(
190 "%s.from_decimal() only takes Decimals, not %r (%s)" %
191 (cls.__name__, dec, type(dec).__name__))
192 return cls(*dec.as_integer_ratio())
193
194 def as_integer_ratio(self):
195 """Return the integer ratio as a tuple.

Callers

nothing calls this directly

Calls 3

as_integer_ratioMethod · 0.95
DecimalClass · 0.90
typeClass · 0.50

Tested by

no test coverage detected