[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/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 7.

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));
//   : ""

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

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

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

locales options .

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

locales Optional

BCP 47 , Intl.NumberFormat() locales .

Intl.NumberFormat , .

options Optional

, Intl.NumberFormat() options .

Intl.NumberFormat .

Intl.NumberFormat() .

.

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

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

toLocaleString()

locale , .

js
const number = 3500;

console.log(number.toLocaleString()); //   "3,500"

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

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

. , locales .

js
const number = 123456.789;

//          
console.log(number.toLocaleString("de-DE"));
// 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

toLocaleString() options .

js
const number = 123456.789;

//   
console.log(
  number.toLocaleString("de-DE", { style: "currency", currency: "EUR" }),
);
// 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