Export (0) Print
Expand All

toLocaleString (Number)

Converts a number to a string by using the current or specified locale.

numberObj.toLocaleString([locales][, options])

numberObj

Required. The Number object to convert.

locales

Optional. An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.

options

Optional. An object that contains one or more properties that specify comparison options.

Starting in Internet Explorer 11, toLocaleString uses Intl.NumberFormat internally to make comparisons, which adds support for the locales and options parameters. For more information about these parameters, see Intl.NumberFormat.

Important note Important

The locales and options parameters are not supported in all document modes and browser versions. For more information, see the Requirements section.

Note Note

If you omit the locales parameter, use toLocaleString only to display results to a user; never use it to compute values within a script, because the returned result is machine-specific (the method returns the current locale).

The following example shows how to use the toLocaleString method with no parameters.

var n, s;
n = new Number(100);
s = "Current locale value is: ";
s += n.toLocaleString();               
document.write(s);

// Output:
// The value 100 as represented by the current locale.

The following example shows how to use the toLocaleString method with a specified locale and comparison options.

var number = 123456789;
var options1 = { style: "percent" };
var options2 = { style: "currency", currency: "INR" };

document.write(number.toLocaleString("en-US"));
// 123,456,789
document.write(number.toLocaleString("ja-JP"));
// 123,456,789
document.write(number.toLocaleString("ar-SA", options1));
// ١٢,٣٤٥,٦٧٨,٩٠٠ %
document.write(number.toLocaleString("hi-IN", options2));
// ₹ 12,34,56,789.00

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

locales and options parameters:

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information. Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

Show:
© 2014 Microsoft