JavaScript
μ«μλ₯Ό k, m, b, μ², λ§, μ΅ λ¨μλ‘ λνλ΄κΈ°
presentKey
2023. 12. 12. 20:12
π© 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));