Class jsworld.MonetaryFormatter
Class for localised formatting of currency amounts.
See:
POSIX LC_MONETARY.
Defined in: <JsWorld.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
jsworld.MonetaryFormatter(locale, currencyCode, altIntSymbol)
Creates a new monetary formatter for the specified locale.
|
Method Attributes | Method Name and Description |
---|---|
currencySymbolPrecedes(intFlag)
Gets the position of the currency symbol relative to
the amount.
|
|
format(amount, options)
Formats a monetary amount according to the preset
locale.
|
|
Gets the currency symbol used in formatting.
|
|
Gets the decimal delimiter (radix) used in formatting.
|
|
getFractionalDigits(intFlag)
Gets the number of fractional digits.
|
Class Detail
jsworld.MonetaryFormatter(locale, currencyCode, altIntSymbol)
Creates a new monetary formatter for the specified locale.
- Parameters:
- {jsworld.Locale} locale
- A locale object specifying the required POSIX LC_MONETARY formatting properties.
- {String} currencyCode Optional
- Set the currency explicitly by passing its international ISO-4217 code, e.g. "USD", "EUR", "GBP". Use this optional parameter to override the default local currency
- {String} altIntSymbol Optional
- Non-local currencies are formatted with their international ISO-4217 code to prevent ambiguity. Use this optional argument to force a different symbol, such as the currency's shorthand sign. This is mostly useful when the shorthand sign is both internationally recognised and identifies the currency uniquely (e.g. the Euro sign).
- Throws:
- Error on constructor failure.
Method Detail
{Boolean}
currencySymbolPrecedes(intFlag)
Gets the position of the currency symbol relative to
the amount. Assumes a non-negative amount and local formatting.
- Parameters:
- {String} intFlag
- Optional flag to force international formatting by passing the string "i".
- Returns:
- {Boolean} True if the symbol precedes the amount, false if the symbol succeeds the amount.
format(amount, options)
Formats a monetary amount according to the preset
locale.
For local currencies the native shorthand symbol will be used for formatting. Example: locale is en_US currency is USD -> the "$" symbol will be used, e.g. $123.45 For non-local currencies the international ISO-4217 code will be used for formatting. Example: locale is en_US (which has USD as currency) currency is EUR -> the ISO three-letter code will be used, e.g. EUR 123.45 If the currency is non-local, but an alternative currency symbol was provided, this will be used instead. Example locale is en_US (which has USD as currency) currency is EUR an alternative symbol is provided - "€" -> the alternative symbol will be used, e.g. €123.45
- Parameters:
- {Number|String} amount
- The amount to format as currency.
- {String} options Optional
- Options to modify the formatted output:
- "^" suppress grouping
- "!" suppress the currency symbol
- "~" suppress the currency symbol and the sign (positive or negative)
- "i" force international sign (ISO-4217 code) formatting
- ".n" specify decimal precision
- Throws:
- "Error: Invalid amount" on bad amount.
- Returns:
- The formatted currency amount as string.
{String}
getCurrencySymbol()
Gets the currency symbol used in formatting.
- Returns:
- {String} The currency symbol.
{String}
getDecimalPoint()
Gets the decimal delimiter (radix) used in formatting.
- Returns:
- {String} The radix character.
{integer Number}
getFractionalDigits(intFlag)
Gets the number of fractional digits. Assumes local
formatting.
- Parameters:
- {String} intFlag
- Optional flag to force international formatting by passing the string "i".
- Returns:
- {integer Number} The number of fractional digits.