This type has the following constructors:

new Money(float:  number): TMoney<'XXX'>;
new Money<C extends CurrencyCode>(float: number,  currency: C): TMoney<C>; 

While working in scripts, it is recommended that you use the constructor that specifies the currency.

const price = new Money(100.5, 'USD');

Currency codes comply with the ISO 4217 standard. This type is immutable, so mutation methods return the updated value without changing the original one.

const price = new Money(100.5, 'USD');
const total = price.multiply(count); 

Type parameters

  • C: CurrencyCode

Hierarchy

  • TMoney

Properties

Readonly cents

cents: number

Number of cents.

Readonly currency

currency: C

Currency (alphabetic code from the ISO 4217 standard).

Methods

add

  • Addition.

    Parameters

    Returns TMoney<C>

asFloat

  • asFloat(): number
  • Decimalization with an accuracy depending on the currency.

    const salary = new Money(101, 'USD');
    const salary2 = salary. multiply(0,001); 
    salary2.asFloat(); // 0.1 
    

    Returns number

multiply

  • multiply(k: number): TMoney<C>
  • Multiply by the number, rounding down the cents.

    Parameters

    • k: number

    Returns TMoney<C>