Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Classe « Decimal » Python 3.11.3

Méthode fractions.Decimal.quantize

Signature de la méthode quantize

def quantize(self, /, exp, rounding=None, context=None) 

Description

help(Decimal.quantize)

Return a value equal to the first operand after rounding and having the
exponent of the second operand.

    >>> 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.