Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Money

A Money represents an amount of money in a given currency.

Money exposes a set of math and comparison operators that can be used to interact with it. The intermediate results of these operations follow f64's behaviour. If Money is included as part of a script's output, then the value is converted to an integer amount of subunits before it is returned from the script.

The following operators are supported by this class: * / == != + - > >= < <=

Hierarchy

  • Money

Index

Accessors

Methods

Accessors

currency

  • Get the Currency value of this Money

    Returns Currency

    The Currency value of this Money

Methods

round

  • Rounds the value of a Money to a step value. The rounding behaviour is defined by the mode parameter.

    Examples:

    • Round up to the dollar: (USD$1.05).round(1, RoundingMode.UP) => USD$2.00
    • Round down to the dollar: (USD$1.05).round(1, RoundingMode.DOWN) => USD$1.00
    • Round to the nearest dollar: (USD$1.05).round(1, RoundingMode.NEAREST) => USD$1.00
    • Round to the nearest dollar: (USD$1.50).round(1, RoundingMode.NEAREST) => USD$2.00
    • Round to the nearest nickel: (USD$1.88).round(0.05, RoundingMode.NEAREST) => USD$1.90
    • Round up to $10: (USD$3.50).round(10, RoundingMode.UP) => USD$10.00

    Parameters

    • step: f64

      The positive step value to round to. The Money will be rounded to a multiple of this value.

    • mode: RoundingMode

      The rounding mode to use.

    Returns Money

    A new Money instance with the rounded value

toString

  • toString(): string
  • Returns string

Static fromAmount

  • Create a Money instance from an amount and currency

    Parameters

    • amount: f64

      The unit amount the Money should represent (For example, $5.25 USD would have amount 5.25)

    • currency: Currency

      The currency that the Money should be in (For example, USD would be Currencies.USD)

    Returns Money

    A new Money instance

Generated using TypeDoc