_locale (Format Currency, Number, Date/Time)
These functions format numbers, currency, date, and time values in localized language/country format.
Functions
| Create new or get default locale object. |
| (As of 3.2.001.01) (Merge only) Set default locale. |
Usage
To use the _locale
features you must create an instance of the _locale
object as follows:
var loc = _locale.create("fr_CA"); // French-Canadian
This new loc
object can now be used to do various conversions to the specified locale (French Canadian in this example). The parameter to _locale.create()
is a string comprised of a 2-character language code, followed by an underscore, followed by a 2-character country code. If you do not supply a locale name (_locale.create()
) then you will get a default locale object. DocOrigin uses the IBM ICU tools to do all locale conversion. They use standard Language Codes specified in the ISO-639 standard. The Country Codes are from the ISO-3166 standard.
Object functions
loc.country() | Returns a 3-character country code. For example when using locale 'en-US' this routine will return "USA". |
loc.currency() | Returns a 3-character currency code. For example when using locale 'en-US' this routine will return "USD". |
| Returns the current date. |
| Returns the current time. |
loc.formatCurrency( num) | Returns a text string formatted according to the current locale's currency conventions. |
loc.formatDate( num[, style]) | Creates a localized date string. |
loc.formatNumber( num) | Returns a number formatted into a text string according to the specified locale's conventions. |
loc.name() | Returns the locale's name (e.g. "fr_CA"). |
loc.parseCurrency( currencystring) | Convert a formatted currency value to JavaScript number. This routine will remove currency symbols and deal correctly with comma vs. dot separators as dictated by the locale. |
loc.parseDate( datestring[, style]) | Convert formatted date to a number. |
loc.parseNumber( numberstring) | Convert formatted number to a JavaScript number. Note that this routine assumes the numberstring is correctly formatted for the locale. For example: var loc = _locale.create("fr_FR"); // France n = loc.parseNumber("12.345,67"); // returns 12345.67 |
loc.spellOut( number[, caps]) | Convert a number to words. This function is only available for a limited number of languages. It converts a number like 154 to "one hundred fifty-four". If caps is set to true the text will be "One Hundred Fifty-four'. |
loc.spellOutCurrency( number, format[, case]) | convert a currency number to words. format is a text string with an embedded var loc = _locale.create("en_US"); this._value = loc.spellOutCurrency(123.46, "*%s Dollars and %d Cents*"); // results in *one hundred and twenty-three Dollars and 46 Cents* this._value = loc.spellOutCurrency(123.46, "*%s Dollars and %d Cents*", "mixed"); // results in *One Hundred and Twenty-three Dollars and 46 Cents* this._value = loc.spellOutCurrency(123.46, "*%s Dollars and %s Cents*", "upper"); // results in *ONE HUNDRED AND TWENTY-THREE Dollars and FORTY-SIX Cents* |