๋ชฉ์ฐจ
๐ฉ Intl
๋ฌธ์์ด, ๋ ์ง ๋ฐ ์๊ฐ, ์ซ์ ๋ฑ ๊ตญ์ ํ ๋ฐ ์ง์ญํ ์์ ์ ์ํํ๋๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
๐ฉ ์ ์ฉํ๊ธฐ
// ์ฒซ ๋ฒ์งธ ์ธ์ locales: ์ง์ญ
// ๋ ๋ฒ์งธ ์ธ์ option
Intl.NumberFormat(locales, {
notation: "compact", // 'compact'
maximumFractionDigits: 1, // ์์ ์๋ฆฌ ํํ
}).format(num);
// 1.2์ฒ
console.log(Intl.NumberFormat('ko-KR', {
notation: "compact",
maximumFractionDigits: 1,
}).format(1234));
// 1.2์ต
console.log(
Intl.NumberFormat("ko-KR", {
notation: "compact",
maximumFractionDigits: 1,
}).format(123456789),
);
// 1.2K
console.log(Intl.NumberFormat('en-US', {
notation: "compact",
maximumFractionDigits: 1,
}).format(1234));
// 123.5M
console.log(Intl.NumberFormat('en-US', {
notation: "compact",
maximumFractionDigits: 1,
}).format(123456789));
๐ฉ Intl
๋ฌธ์์ด, ๋ ์ง ๋ฐ ์๊ฐ, ์ซ์ ๋ฑ ๊ตญ์ ํ ๋ฐ ์ง์ญํ ์์ ์ ์ํํ๋๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
๐ฉ ์ ์ฉํ๊ธฐ
// ์ฒซ ๋ฒ์งธ ์ธ์ locales: ์ง์ญ
// ๋ ๋ฒ์งธ ์ธ์ option
Intl.NumberFormat(locales, {
notation: "compact", // 'compact'
maximumFractionDigits: 1, // ์์ ์๋ฆฌ ํํ
}).format(num);
// 1.2์ฒ
console.log(Intl.NumberFormat('ko-KR', {
notation: "compact",
maximumFractionDigits: 1,
}).format(1234));
// 1.2์ต
console.log(
Intl.NumberFormat("ko-KR", {
notation: "compact",
maximumFractionDigits: 1,
}).format(123456789),
);
// 1.2K
console.log(Intl.NumberFormat('en-US', {
notation: "compact",
maximumFractionDigits: 1,
}).format(1234));
// 123.5M
console.log(Intl.NumberFormat('en-US', {
notation: "compact",
maximumFractionDigits: 1,
}).format(123456789));