
NumberFormatter::format을 사용하여 숫자 형식을 변환할 때, locale을 지정하여 지역별로 숫자 형식을 다르게 적용할 수 있습니다.
locale을 지정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$numberFormatter = new NumberFormatter('ko_KR', NumberFormatter::DECIMAL);
echo $numberFormatter->format(12345.6789); // 12,345.6789
$numberFormatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo $numberFormatter->format(12345.6789); // 12,345.68
위 예시에서는 'ko_KR'과 'en_US'를 locale으로 지정하여 지역별로 숫자 형식을 다르게 적용했습니다.
locale을 지정하지 않고 기본적으로 숫자 형식을 변환할 수 있는 방법은 다음과 같습니다.
#hostingforum.kr
php
$numberFormatter = new NumberFormatter('default', NumberFormatter::DECIMAL);
echo $numberFormatter->format(12345.6789); // 12345.6789
위 예시에서는 'default'를 locale으로 지정하여 기본적으로 숫자 형식을 변환했습니다.
2025-05-15 11:36