Decimal
Decimal module: fixed-point decimal arithmetic for financial math.
Representation: Decimal(coefficient, scale) where coefficient : Int — the unscaled integer value scale : Int — number of decimal places (>= 0)
Examples: 1.23 = Decimal(123, 2) -0.01 = Decimal(-1, 2) 100 = Decimal(100, 0)
All arithmetic normalizes to the higher scale of the two operands, avoiding loss of precision. Round uses half-up (0.5 rounds away from zero).
Interface implementations: impl Eq(Decimal) — eq/2 impl Ord(Decimal) — compare/2 impl Show(Decimal) — show/1
Types
Functions
Creates a Decimal from a native Int with a given scale.
Adds two Decimals. Result has the larger of the two scales.
Subtracts b from a. Result has the larger of the two scales.
Multiplies two Decimals. Result scale is the sum of the two scales.
Divides a by b to precision decimal places using truncation. Panics if b is zero.
Rounds a Decimal to places decimal places using half-up rounding (0.5 rounds away from zero).