Intl.NumberFormat
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2017ë 9ì.
Intl.NumberFormat ì ì¸ì´ì ë§ë ì«ì ììì ì§ìíë ê°ì²´ì ìì±ìì
ëë¤.
ìëí´ ë³´ê¸°
const number = 123456.789;
console.log(
new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(
number,
),
);
// Expected output: "123.456,79 â¬"
// The Japanese yen doesn't use a minor unit
console.log(
new Intl.NumberFormat("ja-JP", { style: "currency", currency: "JPY" }).format(
number,
),
);
// Expected output: "ï¿¥123,457"
// Limit to three significant digits
console.log(
new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 3 }).format(
number,
),
);
// Expected output: "1,23,000"
ìì±ì
Intl.NumberFormat()-
ìë¡ì´
NumberFormatê°ì²´ë¥¼ ìì±í©ëë¤.
ì ì ë©ìë
Intl.NumberFormat.supportedLocalesOf()-
주ì´ì§ ë¡ì¼ì¼ ëª©ë¡ ì¤, ë°íìì´ ì§ìíë í목ì ë°°ì´ë¡ ë°íí©ëë¤.
ì¸ì¤í´ì¤ ìì±
ìë ìì±ì Intl.NumberFormat.prototypeì ì ìëì´ ìì¼ë©° 모ë Intl.NumberFormatì´ ì´ ìì±ì ê³µì ë©ëë¤.
Intl.NumberFormat.prototype.constructor-
ì¸ì¤í´ì¤ ê°ì²´ë¥¼ ìì±í ìì±ì í¨ìì ëë¤.
Intl.NumberFormatì¸ì¤í´ì¤ì ê²½ì°, ì´ê¸° ê°ìIntl.NumberFormatìì±ìì ëë¤. Intl.NumberFormat.prototype[@@toStringTag]-
@@toStringTagìì±ì ì´ê¸°ê°ì¸ 문ìì´"Intl.NumberFormat"ì ëë¤. ì´ ìì±ìObject.prototype.toString()ìì ì¬ì©í©ëë¤.
ì¸ì¤í´ì¤ ë©ìë
Intl.NumberFormat.prototype.format()-: ì´Intl.NumberFormatê°ì²´ì ë¡ì¼ì¼ê³¼ íì ìµì ì ë°ë¼ ì«ì를 íìííë ì ê·¼ì í¨ìì ëë¤.Intl.NumberFormat.prototype.formatRange()- : ë©ìëê° í¸ì¶ë ì´
Intl.NumberFormatê°ì²´ì ë¡ì¼ì¼ê³¼ íì ìµì ì ë°ë¼ ë²ì를 íìííë ì ê·¼ì í¨ìì ëë¤.
- : ë©ìëê° í¸ì¶ë ì´
Intl.NumberFormat.prototype.formatRangeToParts()- : ì¬ì©ì ì§ì ë¡ì¼ì¼ ì¸ì íì ì§ì ì ì¬ì©í ì ìë ì«ì 문ìì´ì ë²ì를 ë¶ë¶ì ì¼ë¡ ëíë´ë ê°ì²´ì
Array를 ë°íí©ëë¤.
- : ì¬ì©ì ì§ì ë¡ì¼ì¼ ì¸ì íì ì§ì ì ì¬ì©í ì ìë ì«ì 문ìì´ì ë²ì를 ë¶ë¶ì ì¼ë¡ ëíë´ë ê°ì²´ì
Intl.NumberFormat.prototype.formatToParts()- : ì¬ì©ì ì§ì ë¡ì¼ì¼ ì¸ì íì ì§ì ì ì¬ì©í ì ìë ì«ì 문ìì´ì ë¶ë¶ì ì¼ë¡ ëíë´ë ê°ì²´ì
Array를 ë°íí©ëë¤.
- : ì¬ì©ì ì§ì ë¡ì¼ì¼ ì¸ì íì ì§ì ì ì¬ì©í ì ìë ì«ì 문ìì´ì ë¶ë¶ì ì¼ë¡ ëíë´ë ê°ì²´ì
Intl.NumberFormat.prototype.resolvedOptions()- : ê°ì²´ë¥¼ ì´ê¸°ííë ëì ê³ì°ë ë¡ì¼ì¼ ë° ë°ì´í° ì ë ¬ ìµì ì ë°ìíë ìì±ì´ í¬í¨ë ì ê°ì²´ë¥¼ ë°íí©ëë¤.
ìì
>기본ì ì¸ ì¬ì© ë°©ë²
ë¡ì¼ì¼ì ì§ì íì§ ìê³ ì¬ì©íë©´ 기본 ë¡ì¼ì¼ ë° ê¸°ë³¸ ìµì ììì ì ì©í 문ìì´ì ë°íí©ëë¤.
const number = 3500;
console.log(new Intl.NumberFormat().format(number));
// â íêµ ë¡ì¼ì¼ì ê²½ì° '3,500' íì
locales ì¬ì©í기
ë¤ì ìì ë ì§ìíë ì«ì ììì ìì를 ë³´ì
ëë¤. ì´í리ì¼ì´ì
ì ì¬ì©ì ì¸í°íì´ì¤ ì¸ì´ì ë§ë ììì ì ì©íë ¤ë©´ locales 매ê°ë³ìë¡ ì ì í ì¸ì´(ì, íìí ê²½ì° ëì²´ ì¸ì´)를 ì ê³µíë걸 ìì§ ë§ì¸ì.
const number = 123456.789;
// ë
ì¼ì ììì 구ë¶ìë¡ ì¼í를 ì¬ì©íê³ ì² ë¨ì 구ë¶ìë¡ ë§ì¹¨í를 ì¬ì©
console.log(new Intl.NumberFormat("de-DE").format(number));
// 123.456,789
// ëë¶ë¶ì ìëì´ ì¬ì© êµê°ììë ì¤ì ìë¼ë¹ì ì«ì를 ì¬ì©
console.log(new Intl.NumberFormat("ar-EG").format(number));
// ١٢٣٤٥٦٫٧٨٩
// ì¸ëë ì², ë¼í¬(ìë§), í¬ë¡ë¥´(ì²ë§) ë¨ìì 구ë¶ì ì¬ì©
console.log(new Intl.NumberFormat("en-IN").format(number));
// 1,23,456.789
// nu íì¥ í¤ë¡ 기ìë² ì§ì (ìë ììë ì¤êµì ì«ì í기)
console.log(new Intl.NumberFormat("zh-Hans-CN-u-nu-hanidec").format(number));
// ä¸äºä¸,åäºå
.ä¸å
«ä¹
// ë°ë¦¬ì´ì ê°ì´ ì§ìëì§ ìì ìë ìë ì¸ì´ë¥¼ ì§ì í ëë
// ë¤ìê³¼ ê°ì´ ëì²´ ì¸ì´ë¥¼ ì§ì í ì ìì. ìëì ê²½ì° ëì²´ ì¸ì´ë ì¸ëì´
console.log(new Intl.NumberFormat(["ban", "id"]).format(number));
// 123.456,789
options ì¬ì©
options 매ê°ë³ì를 ì§ì í´ ê²°ê³¼ë¥¼ ìíë ííë¡ ë°ê¿ ì ììµëë¤.
const number = 123456.789;
// íµí ìì
console.log(
new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(
number,
),
);
// 123.456,79 â¬
// íêµ ìíë ë³´ì¡° íµí ë¨ì를 ì¬ì©íì§ ìì
console.log(
new Intl.NumberFormat("ko-KR", { style: "currency", currency: "KRW" }).format(
number,
),
);
// â©123,457
// ì í¨ì«ì를 ì¸ ê°ë¡ ì í
console.log(
new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 3 }).format(
number,
),
);
// 1,23,000
// ë¨ìì ë°ë¼ íì ì§ì
console.log(
new Intl.NumberFormat("pt-PT", {
style: "unit",
unit: "kilometer-per-hour",
}).format(50),
);
// 50 km/h
console.log(
(16).toLocaleString("en-GB", {
style: "unit",
unit: "liter",
unitDisplay: "long",
}),
);
// 16 litres
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Internationalization API Specification> # numberformat-objects> |