Python‎ > ‎decimal‎ > ‎

Decimal.compare_total()


Definition
compare_total(other, context=None) - Compare two operands using their abstract representation rather than their numerical value. Similar to the compare() method, but the result gives a total ordering on Decimal instances.

Syntax
Decimal(x).compare_total(Decimal(y)=Decimal(z)

Parameters
Decimal(x)

Examples
The examples are:
 >>> Decimal(33.21).compare_total(Decimal(22.12))
Decimal('1')
>>> Decimal(11.21).compare_total(Decimal(123.12))
Decimal('-1')
>>>

The equivalent to following returns:
>>> a=Decimal(22.1).compare_total(22)
>>> b=Decimal(10.1).compare_total(33)
>>> operator.sub(a,b)
Decimal('2')
>>> operator.gt(a,b)
True
>>> operator.ifloordiv(a,b)
Decimal('-1')
>>> operator.imod(a,b)
Decimal('0')
>>>



Comments