Module: Utils/Currency

Currency module provides utility methods for working with currencies.

Methods


<static> convertAmount(amount, fromId, toId)

Converts from one currency to another.

Parameters:
Name Type Description
amount number | string

Base currency amount.

fromId string

Source currency id.

toId string

Target currency id.

Returns:

The converted amount.

Type
string

<static> convertFromBase(amount, toId)

Converts from the base currency to another currency.

Parameters:
Name Type Description
amount number | string

The amount in the base currency.

toId string

Target currency id.

Returns:

The converted amount.

Type
string

<static> convertToBase(amount, fromId)

Converts a currency to the base currency.

Parameters:
Name Type Description
amount number | string

The amount in the source currency.

fromId string

Source currency id.

Returns:

The converted amount.

Type
string

<static> convertWithRate(amount, fromRate, toRate)

Converts a currency with given conversion rates.

Parameters:
Name Type Description
amount number | string

The amount in the origin currency.

fromRate number

The origin conversion rate relative to the base currency.

toRate number

The target conversion rate relative to the base currency.

Returns:

The converted amount.

Type
string

<static> formatAmount(amount [, currencyId] [, decimalPrecision] [, numberGroupingSeparator] [, decimalSeparator] [, symbolSeparator])

Formats a currency amount.

Parameters:
Name Type Argument Default Description
amount number

The amount to be formatted.

currencyId string <optional>

The currency id to be used. If not specified, the system default will be used.

decimalPrecision number <optional>
2

The number of digits for decimal precision.

numberGroupingSeparator string <optional>
','

The thousands separator.

decimalSeparator string <optional>
'.'

The decimal separator (string between number and decimal digits).

symbolSeparator string <optional>
''

The string between the symbol and the amount.

Returns:

The formatted currency amount.

Type
string

<static> formatAmountLocale(amount [, currencyId] [, decimalPrecision])

Formats a currency amount according to the current user's locale.

Parameters:
Name Type Argument Description
amount number

The amount to format.

currencyId string <optional>

The currency id to use. If not specified, the system default will be used.

decimalPrecision string <optional>

The number of decimal digits to use. If not specified, the user preference will be used.

Returns:

formatted currency amount.

Type
string

<static> getBaseCurrency()

Gets the system's base currency.

Returns:

The base currency data.

Type
Object

<static> getBaseCurrencyId()

Gets the base currency id.

Returns:

The base currency id.

Type
string

<static> getCurrenciesSelector(template)

Returns a map of currency IDs to the result of applying the given Handlebars template to them.

Example for the template param:

  getCurrenciesSelector(Handlebars.compile('{{symbol}} ({{iso}})'));
Parameters:
Name Type Description
template function

How to format the values returned.

Returns:

Map from currency IDs to formatted currency data.

Type
Object

<static> getCurrencySymbol(currencyId)

Gets the symbol for the given currency ID.

Parameters:
Name Type Description
currencyId string

Currency identifier.

Returns:

The currency display symbol (e.g. "$").

Type
string

<static> unformatAmount(amount, numberGroupingSeparator, decimalSeparator [, toFloat])

Unformats a currency amount.

Parameters:
Name Type Argument Default Description
amount string

The amount to unformat.

numberGroupingSeparator string

Thousands separator.

decimalSeparator string

The string between number and decimals.

toFloat boolean <optional>
false

If true, convert string to float value.

Returns:

The unformatted currency amount.

Type
string

<static> unformatAmountLocale(amount, toFloat)

Unformats the currency amount according to the current user's locale.

Parameters:
Name Type Description
amount string

Amount to unformat.

toFloat boolean

If true, convert string to float value.

Returns:

The unformatted currency amount.

Type
string