Options
All
  • Public
  • Public/Protected
  • All
Menu

Helper class for dealing with amounts.

Hierarchy

  • Amounts

Index

Constructors

Private constructor

  • Returns Amounts

Methods

Static add

  • Add two amounts. Return the result and whether the addition overflowed. The overflow is always handled by saturating and never by wrapping.

    Throws when currencies don't match.

    Parameters

    Returns Result

Static check

  • check(a: any): boolean
  • Check if the argument is a valid amount in string form.

    Parameters

    • a: any

    Returns boolean

Static cmp

  • Compare two amounts. Returns 0 when equal, -1 when a < b and +1 when a > b. Throws when currencies don't match.

    Parameters

    Returns 0 | 1 | -1

Static copy

  • Create a copy of an amount.

    Parameters

    Returns AmountJson

Static divide

  • Divide an amount. Throws on division by zero.

    Parameters

    Returns AmountJson

Static fromFloat

  • fromFloat(floatVal: number, currency: string): AmountJson
  • Convert a float to a Taler amount. Loss of precision possible.

    Parameters

    • floatVal: number
    • currency: string

    Returns AmountJson

Static getZero

  • Get an amount that represents zero units of a currency.

    Parameters

    • currency: string

    Returns AmountJson

Static isNonZero

  • Check if an amount is non-zero.

    Parameters

    Returns boolean

Static isZero

  • Parameters

    Returns boolean

Static jsonifyAmount

Static max

Static min

Static mult

  • Parameters

    Returns Result

Static parse

  • Parse an amount like 'EUR:20.5' for 20 Euros and 50 ct.

    Parameters

    • s: string

    Returns undefined | AmountJson

Static parseOrThrow

  • Parse amount in standard string form (like 'EUR:20.5'), throw if the input is not a valid amount.

    Parameters

    • s: string

    Returns AmountJson

Static stringify

  • Convert to standard human-readable string representation that's also used in JSON formats.

    Parameters

    Returns string

Static sub

  • Subtract two amounts. Return the result and whether the subtraction overflowed. The overflow is always handled by saturating and never by wrapping.

    Throws when currencies don't match.

    Parameters

    Returns Result

Static sum

  • Parameters

    Returns Result

Generated using TypeDoc