Options
All
  • Public
  • Public/Protected
  • All
Menu

A discrete monetary value.

A discrete value is always an integer multiple of a currency unit.

Discrete instances are immutable.

A discrete value is based on a scale. The scale is the ratio between the chosen unit and the main currency unit.

const euroCent = Discrete.scale("EUR", "cent", Rational.of(100, 1));
const euro = Discrete.scale("EUR", "euro", Rational.of(1, 1));
Discrete.of(42, euroCent).add(Discrete.of(23, euro)); // type error, euro is not assignable to cent

Type parameters

  • Currency: string

  • Unit: string

Hierarchy

  • Discrete

Index

Properties

Readonly scale

scale: Scale<Currency, Unit>

Readonly value

value: bigint

Methods

add

  • adds the given discrete value to this value

    Parameters

    • that: Discrete<Currency, Unit>

      the discrete value to add

    Returns Discrete<Currency, Unit>

decrement

dense

  • dense(): Dense<Currency>

increment

mul

  • mul(x: bigint | number): Discrete<Currency, Unit>
  • multiplies this value by the given factor

    Parameters

    • x: bigint | number

      the factor to multiply by

    Returns Discrete<Currency, Unit>

sub

  • subtracts the given discrete value from this value

    Parameters

    • that: Discrete<Currency, Unit>

      the discrete value to subtract

    Returns Discrete<Currency, Unit>

toDecimal

  • toDecimal(): string
  • formats this discrete value as a decimal string

    Returns string

Static of

  • of<Currency, Unit>(value: bigint | number, scale: Scale<Currency, Unit>): Discrete<Currency, Unit>
  • creates a new discrete value with the given amount and scale

    Type parameters

    • Currency: string

    • Unit: string

    Parameters

    • value: bigint | number

      the unit amount

    • scale: Scale<Currency, Unit>

      the unit scale

    Returns Discrete<Currency, Unit>

Static scale

  • scale<Currency, Unit>(currency: Currency, tag: Unit, ratio: Rational): Scale<Currency, Unit>
  • creates a new scale based on the given currency, unit and ratio

    const euroCent = Discrete.scale("EUR", "cent", Rational.of(100, 1));
    const euro = Discrete.scale("EUR", "euro", Rational.of(1, 1));
    const usdCent = Discrete.scale("USD", "cent", Rational.nat(100));
    const xauTroyOunce = Discrete.scale("XAU", "troy-ounce", Rational.nat(1));
    const xauGram = Discrete.scale("XAU", "gram", Rational.fromDecimal("31.103477"));

    Type parameters

    • Currency: string

    • Unit: string

    Parameters

    • currency: Currency

      the currency name

    • tag: Unit

      the unit name

    • ratio: Rational

      the ratio between the unit and the currency main unit

    Returns Scale<Currency, Unit>

Legend

Generated using TypeDoc