Currency module provides utility methods for working with currencies.
Methods
#
(static) convertAmount(amount, fromId, toId) → {string}
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. |
#
(static) convertFromBase(amount, toId) → {string}
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. |
#
(static) convertToBase(amount, fromId) → {string}
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. |
#
(static) convertWithRate(amount, fromRate, toRate) → {string}
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. |
Formats a currency amount.
Parameters:
Name |
Type |
Attributes |
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
Formats a currency amount according to the current user's locale.
Parameters:
Name |
Type |
Attributes |
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() → {Object}
Gets the system's base currency.
#
(static) getBaseCurrencyId() → {string}
Gets the base currency id.
#
(static) getCurrenciesSelector(template) → {Object}
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) → {string}
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
Unformats a currency amount.
Parameters:
Name |
Type |
Attributes |
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
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