--- title: Intl.NumberFormat slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat tags: - Internationalization - Intl - JavaScript - NumberFormat - Reference translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat ---
Intl.NumberFormat
은 언어에 맞는 숫자 서식을 지원하는 객체의 생성자입니다.
new Intl.NumberFormat([locales[, options]]) Intl.NumberFormat.call(this[, locales[, options]])
locales
{{optional_inline}}BCP 47 언어 태그를 포함하는 문자열이나 문자열의 배열. 로케일 매개변수의 일반적인 형식 및 해석은 {{jsxref("Intl", "Intl
문서", "#Locale_identification_and_negotiation", 1)}}를 참고하세요. 다음의 Unicode 확장 키를 사용할 수 있습니다.
nu
"arab"
, "arabext"
, "bali"
, "beng"
, "deva"
, "fullwide"
, "gujr"
, "guru"
, "hanidec"
, "khmr"
, "knda"
, "laoo"
, "latn"
, "limb"
, "mlym"
, "mong"
, "mymr"
, "orya"
, "tamldec"
, "telu"
, "thai"
, "tibt"
등을 사용할 수 있습니다.options
{{optional_inline}}다음 속성을 포함하는 객체.
localeMatcher
"lookup"
과 "best fit"
이고, 기본값은 "best fit"
입니다. 자세한 정보는 {{jsxref("Intl", "Intl
문서", "#로케일_조정", 1)}}를 참고하세요.style
"decimal"
, 통화 서식 "currency"
, 백분율 서식 "percent"
입니다. 기본값은 "decimal"
입니다.currency
"KRW"
, 미국 달러화 "USD"
, 유럽 유로화 "EUR"
등을 포함합니다. 현재 통화 및 펀드 코드 목록을 참고하세요. 기본값은 없습니다. style
값을 "currency"
로 지정했다면, currency
값도 반드시 지정해야 합니다.currencyDisplay
"symbol"
, ISO 통화 코드를 사용하는 "code"
, "dollar"
등 현지 통화 이름을 사용하는 "name"
이 있습니다. 기본 값은 "symbol"
입니다.useGrouping
true
와 false
입니다. 기본 값은 true
입니다.아래 속성은 두 가지 그룹으로 나뉩니다. minimumIntegerDigits
, minimumFractionDigits
, maximumFractionDigits
가 첫 번째 그룹이고, minimumSignificantDigits
와 maximumSignificantDigits
가 두 번째 그룹으로, 두 번째 그룹 중 하나라도 지정하면 첫 번째 그룹은 모두 무시합니다.
minimumIntegerDigits
minimumFractionDigits
maximumFractionDigits
minimumFractionDigits
와 3 중 더 큰 값입니다. 통화 서식의 기본값은 minimumFractionDigits
와, ISO 4217 통화 코드 목록이 제공하는 보조 단위의 자릿수(목록에 정보가 없을 경우 2) 중 더 큰 값입니다. 백분율 서식의 기본값은 minimumFractionDigits
와 0 중 더 큰 값입니다.minimumSignificantDigits
maximumSignificantDigits
NumberFormat
인스턴스NumberFormat
인스턴스는 프로토타입의 다음 속성을 상속합니다.
NumberFormat
인스턴스는 프로토타입의 다음 메서드를 상속합니다.
로케일을 지정하지 않고 사용하면 기본 로케일 및 기본 옵션 서식을 적용한 문자열을 반환합니다.
var number = 3500; console.log(new Intl.NumberFormat().format(number)); // → 한국 로케일의 경우 '3,500' 표시
locales
사용하기다음 예제는 지역화된 숫자 서식의 예시를 보입니다. 어플리케이션의 사용자 인터페이스 언어에 맞는 서식을 적용하려면 locales
매개변수로 적절한 언어(와, 필요한 경우 대체 언어)를 제공하는걸 잊지 마세요.
var 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
매개변수를 지정해 결과를 원하는 형태로 바꿀 수 있습니다.
var 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
명세 | 상태 | Comment |
---|---|---|
{{SpecName('ES Int 1.0', '#sec-11.1', 'Intl.NumberFormat')}} | {{Spec2('ES Int 1.0')}} | 초기 정의. |
{{SpecName('ES Int 2.0', '#sec-11.1', 'Intl.NumberFormat')}} | {{Spec2('ES Int 2.0')}} | |
{{SpecName('ES Int Draft', '#numberformat-objects', 'Intl.NumberFormat')}} | {{Spec2('ES Int Draft')}} |
{{Compat("javascript.builtins.Intl.NumberFormat")}}