[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString [Back]  [Original]

Number.prototype.toLocaleString() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Number.prototype.toLocaleString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

toLocaleString() Number . Intl.NumberFormat API Intl.NumberFormat.

toLocaleString , . , Intl.NumberFormat format(), NumberFormat , format .

In this article

function eArabic(x) {
  return x.toLocaleString("ar-EG");
}

console.log(eArabic(123456.789));
// Expected output: ""

console.log(eArabic("123456.789"));
// Expected output: "123456.789"

console.log(eArabic(NaN));
// Expected output: " "

js
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)

locales options , , .

, Intl.NumberFormat API, Intl.NumberFormat(). Intl.NumberFormat , .

locales

BCP 47 . locales `Intl.NumberFormat().

Intl.NumberFormat .

options

. options Intl.NumberFormat().

Intl.NumberFormat .

Intl.NumberFormat() .

, .

Intl.NumberFormat new Intl.NumberFormat(locales, options).format(number).

: , toLocaleString(), . , . toLocaleString() .

toLocaleString()

, .

js
var number = 3500;

console.log(number.toLocaleString()); //  '3,500'   U.S. English

locales options

locales options . toLocaleString() , , . , locales options, Intl API, :

js
function toLocaleStringSupportsLocales() {
  return (
    typeof Intl === "object" &&
    !!Intl &&
    typeof Intl.DateTimeFormat === "function"
  );
}

locales

. , , , (, , ) locales:

js
var number = 123456.789;

//           ,      
console.log(number.toLocaleString("de-DE"));
// 123.456,789

//           ,      
console.log(number.toLocaleString("ru-RU"));
// 123 456,789

//        
console.log(number.toLocaleString("ar-EG"));
// 

//      //
console.log(number.toLocaleString("en-IN"));
// 1,23,456.789

//   nu   , ,  
console.log(number.toLocaleString("zh-Hans-CN-u-nu-hanidec"));
// ,.

//      , 
// ,    ,    
console.log(number.toLocaleString(["ban", "id"]));
// 123.456,789

options

, toLocaleString(), options:

js
var number = 123456.789;

//   
console.log(
  number.toLocaleString("de-DE", { style: "currency", currency: "EUR" }),
);
// 123.456,79 

console.log(
  number.toLocaleString("ru-RU", { style: "currency", currency: "RUB" }),
);
// 123 456,79 

//      
console.log(
  number.toLocaleString("ja-JP", { style: "currency", currency: "JPY" }),
);
// 123,457

//     
console.log(number.toLocaleString("en-IN", { maximumSignificantDigits: 3 }));
// 1,23,000

//        
const num = 30000.65;
console.log(
  num.toLocaleString(undefined, {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
  }),
);
// "30,000.65"      
// "30.000,65"      
// "30 000,65"     

Specification
ECMAScript 2027 LanguageSpecification
# sec-number.prototype.tolocalestring
ECMAScript 2027 Internationalization API Specification
# sup-number.prototype.tolocalestring


Web Proxy Viewer  |  New URL  |  Original Page