open-nav
    Preparing search index...

    Class Decimal

    An exact decimal, held as a scaled integer.

    The NAV schemas make binary floating point untenable: MonetaryType allows 18 significant digits, QuantityType allows 22 with 10 decimal places, and a VAT rate of 0.27 has no exact double representation. Since NAV rejects a batch whose lines fail to reconcile with its summary, every amount is carried through as an exact value and rounded only where the rules say to round.

    Index
    scale: number

    Number of decimal places.

    units: bigint

    Value as an integer, scaled by 10 ** scale.

    ONE: Decimal = ...
    ZERO: Decimal = ...
    • Build a decimal from an exact representation.

      A number is accepted for convenience and taken as its shortest round-trippable decimal string, so Decimal.from(1.5) is 1.5; a non-finite number is rejected. But a float cannot represent every decimal exactly, and a value whose magnitude renders in exponential notation (such as 1e-7 or 1e21) is not accepted as a number. Pass such values — and any amount where exactness matters — as a string.

      Parameters

      • value: string | number | bigint | Decimal

      Returns Decimal