라이브러리

[PHP] NumberFormatter::getPattern - 포매터 패턴 가져오기




NumberFormatter::getPattern은 PHP의 Intl extension에서 제공하는 함수로, 특정 지역의 숫자 패턴을 반환합니다. 이 패턴은 숫자를 표현하는 데 사용되는 규칙을 포함합니다.

NumberFormatter::getPattern 사용법


NumberFormatter::getPattern 함수는 다음 형식으로 사용됩니다.

#hostingforum.kr
php

 IntlNumberFormatter::getPattern($locale)



- `$locale` : 숫자 패턴을 반환할 지역 코드를 지정합니다. 예를 들어, 'ko-KR'은 한국의 숫자 패턴을 반환합니다.

예제


다음 예제는 한국의 숫자 패턴을 반환하는 코드입니다.

#hostingforum.kr
php

$numberFormatter = new IntlNumberFormatter('ko-KR');

$pattern = $numberFormatter->getPattern();



echo "한국의 숫자 패턴: $pattern";



이 코드를 실행하면 다음과 같은 결과가 출력됩니다.

#hostingforum.kr


한국의 숫자 패턴: #,##0



이 패턴은 숫자를 표현하는 데 사용되는 규칙을 포함합니다. '#'은 숫자를 표현하는 데 사용되는 자릿수를 나타내며, ','은 천의 자릿수를 구분하는 기호입니다.

다른 지역의 숫자 패턴


다음 예제는 다른 지역의 숫자 패턴을 반환하는 코드입니다.

#hostingforum.kr
php

$numberFormatterEn = new IntlNumberFormatter('en-US');

$patternEn = $numberFormatterEn->getPattern();



$numberFormatterFr = new IntlNumberFormatter('fr-FR');

$patternFr = $numberFormatterFr->getPattern();



echo "미국 영어의 숫자 패턴: $patternEn";

echo "
";

echo "프랑스어의 숫자 패턴: $patternFr";



이 코드를 실행하면 다음과 같은 결과가 출력됩니다.

#hostingforum.kr


미국 영어의 숫자 패턴: #,##0.00

프랑스어의 숫자 패턴: #,##0



이 예제에서 미국 영어의 숫자 패턴은 ','으로 천의 자릿수를 구분하고 '.'으로 소수점을 구분하는 반면, 프랑스어의 숫자 패턴은 ','으로 천의 자릿수를 구분합니다.

참고


NumberFormatter::getPattern 함수는 Intl extension이 설치되어 있어야 사용할 수 있습니다. Intl extension은 PHP 5.3.2 이상에서 사용할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 371 페이지

검색

게시물 검색