PHP money_format() 함수
예시
국제 en_US 형식:
<?php
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);
?>
위 코드의 출력은 다음과 같습니다.
The price is USD 1,234.56
정의 및 사용
money_format() 함수는 통화 문자열 형식의 문자열을 반환합니다.
이 함수는 기본 문자열에 백분율(%) 기호가 있는 서식이 지정된 숫자를 삽입합니다.
참고: money_format() 함수는 Windows 플랫폼에서 작동하지 않습니다.
팁: 이 함수는 종종 setlocale() 함수 와 함께 사용됩니다 .
팁: 사용 가능한 모든 언어 코드를 보려면 언어 코드 참조로 이동하십시오.
통사론
money_format(string,number)
매개변수 값
Parameter | Description |
---|---|
string | Required. Specifies the string to be formatted and how to format the variables in it. Possible format values: Padding and Flags:
Field width:
Conversion characters:
Note: If multiple format values are used, they must be in the same order as shown above. Note: This function is affected by local settings. |
number | Required. The number to be inserted at the %-sign in the format string |
기술적 세부 사항
반환 값: | 형식이 지정된 문자열을 반환합니다. 서식 문자열 앞뒤의 문자는 변경되지 않고 반환됩니다. 숫자가 아닌 숫자는 NULL을 반환하고 E_WARNING을 발생시킵니다. |
---|---|
PHP 버전: | 4.3.0+ |
더 많은 예
예시
국제 형식(독일)(소수점 2자리 포함):
<?php
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>
위 코드의 출력은 다음과 같습니다.
1 234,56 EUR
예시
음수, ()가 있는 미국 국가 형식은 음수와 올바른 정밀도의 2자리 숫자를 나타내고 "*"는 채우기 문자로 나타냅니다.
<?php
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>
위 코드의 출력은 다음과 같습니다.
(******1234.57)
❮ PHP 문자열 참조