The toLocaleString()
method returns a string representing the elements of the typed array. The elements are converted to strings and are separated by a locale-specific string (such as a comma “,”). This method has the same algorithm as Array.prototype.toLocaleString()
and, as the typed array elements are numbers, the same algorithm as Number.prototype.toLocaleString()
applies for each element. TypedArray is one of the typed array types here.
typedarray.toLocaleString([locales [, options]]);
locales
Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales
argument, see the Intl page. The following Unicode extension key is allowed:
nu
"arab"
, "arabext"
, "bali"
, "beng"
, "deva"
, "fullwide"
, "gujr"
, "guru"
, "hanidec"
, "khmr"
, "knda"
, "laoo"
, "latn"
, "limb"
, "mlym"
, "mong"
, "mymr"
, "orya"
, "tamldec"
, "telu"
, "thai"
, "tibt"
.options
Optional. An object with some or all of the following properties:
localeMatcher
"lookup"
and "best fit"
; the default is "best fit"
. For information about this option, see the Intl page.style
"decimal"
for plain number formatting, "currency"
for currency formatting, and "percent"
for percent formatting; the default is "decimal"
.currency
"USD"
for the US dollar, "EUR"
for the euro, or "CNY"
for the Chinese RMB — see the Current currency & funds code list. There is no default value; if the style
is "currency"
, the currency
property must be provided.currencyDisplay
"symbol"
to use a localized currency symbol such as €, "code"
to use the ISO currency code, "name"
to use a localized currency name such as "dollar"
; the default is "symbol"
.useGrouping
true
and false
; the default is true
.The following properties fall into two groups: minimumIntegerDigits
, minimumFractionDigits
, and maximumFractionDigits
in one group, minimumSignificantDigits
and maximumSignificantDigits
in the other. If at least one property from the second group is defined, then the first group is ignored.
minimumIntegerDigits
minimumFractionDigits
maximumFractionDigits
minimumFractionDigits
and 3; the default for currency formatting is the larger of minimumFractionDigits
and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information); the default for percent formatting is the larger of minimumFractionDigits
and 0.minimumSignificantDigits
maximumSignificantDigits
minimumSignificantDigits
.A string representing the elements of the typed array.
toLocaleString
var uint = new Uint32Array([2000, 500, 8123, 12, 4212]); uint.toLocaleString(); // if run in a de-DE locale // "2.000,500,8.123,12,4.212" uint.toLocaleString('en-US'); // "2,000,500,8,123,12,4,212" uint.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' }); // "¥2,000,¥500,¥8,123,¥12,¥4,212"
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'TypedArray.prototype.toLocaleString' in that specification. | Standard | Initial definition. |
ECMAScript 2017 Draft (ECMA-262) The definition of 'TypedArray.prototype.toLocaleString' in that specification. | Draft |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 51 (51) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 51.0 (51) | (Yes) | (Yes) | (Yes) |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toLocaleString