PyDocs

Nav

Numeric and Mathematical Modules

Decimal.quantize

decimal

method of Decimal
  • Decimal.quantize(exp, rounding=None, context=None)
Quantize *self* so its exponent is the same as that of *exp*.

Return a value equal to *self* after rounding, with the exponent
of *exp*.

    >>> Decimal('1.41421356').quantize(Decimal('1.000'))
    Decimal('1.414')

Unlike other operations, if the length of the coefficient after the
quantize operation would be greater than precision, then an
InvalidOperation is signaled.  This guarantees that, unless there
is an error condition, the quantized exponent is always equal to
that of the right-hand operand.

Also unlike other operations, quantize never signals Underflow, even
if the result is subnormal and inexact.

If the exponent of the second operand is larger than that of the
first, then rounding may be necessary.  In this case, the rounding
mode is determined by the rounding argument if given, else by the
given context argument; if neither argument is given, the rounding
mode of the current thread's context is used.
1 Example
>>> Decimal('1.41421356').quantize(Decimal('1.000'))
Decimal('1.414')
from the Python docs
See Also
No see-alsos for decimal/Decimal.quantize
0 Notes
No notes for Decimal.quantize