PyDocs

Nav

Numeric and Mathematical Modules

Context.create_decimal_from_float

decimal

method of Context · Added in 3.1
  • Context.create_decimal_from_float(f, /)
Create a new Decimal instance from float f.

Unlike the Decimal.from_float() class method, this function observes
the context limits.
1 Example
>>> context = Context(prec=5, rounding=ROUND_DOWN)
>>> context.create_decimal_from_float(math.pi)
Decimal('3.1415')
>>> context = Context(prec=5, traps=[Inexact])
>>> context.create_decimal_from_float(math.pi)
Traceback (most recent call last):
    ...
decimal.Inexact: None
from the Python docs
See Also
No see-alsos for decimal/Context.create_decimal_from_float
0 Notes
No notes for Context.create_decimal_from_float