all Python 3Numbers & mathterm
decimal.DecimalTuple
decimal
The named tuple (sign, digits, exponent) returned by Decimal.as_tuple(): the sign, digits and exponent of a number.
Syntax
Decimal(x).as_tuple() -> DecimalTuple(sign, digits, exponent)
sign is 0 for positive and 1 for negative numbers, not +1/-1. The tuple keeps the representation, not the value: Decimal('1.2') and Decimal('1.20') are equal, but their tuples differ. The class has no entry of its own in the docs; it is mostly used to count decimal places, which is -exponent.
Examples
from decimal import Decimal
print(Decimal('-1.50').as_tuple()) # → DecimalTuple(sign=1, digits=(1, 5, 0), exponent=-2)
from decimal import Decimal
print(Decimal('1.2') == Decimal('1.20')) # → True
print(Decimal('1.2').as_tuple() == Decimal('1.20').as_tuple()) # → False
from decimal import Decimal
print(Decimal((0, (3, 1, 4), -2))) # → 3.14
See also
Open in the full glossarydocs.python.orgReport an inaccuracy