PHP money_format() 函數(shù)
定義和用法
money_format() 函數(shù)把字符串格式化為貨幣字符串。
語法
money_format(string,number)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要格式化的字符串。 |
number | 可選。被插入格式化字符串中 % 符號位置的數(shù)字。 |
提示和注釋
注釋:money_format() 函數(shù)無法在 windows 平臺上工作。
例子
例子 1
國際 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
例子 2
負數(shù),帶有 () 指示負數(shù)的 US 國際格式,右側(cè)精度為 2,"*" 為填充字符:
<?php
$number = -1234.5672;
echo money_format("%=*(#10.2n", $number)
;
?>
輸出:
($********1,234.57)