PHP money_format () function
Examples
en_US international format:
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);
?>
The code above will output:
Definition and Usage
money_format () function returns a string formatted as a currency string.
This function inserts a formatted number in the percent main strings (%) position.
Note: money_format () function does not work on a Windows platform.
Tip: This function is often the setlocale () function is used together.
Tip: To view all available language codes, please visit our language code reference manual .
grammar
参数 | 描述 |
---|---|
string | 必需。规定要格式化的字符串及如何格式化字符串中的变量。 可能的格式值: 填充和标志:
字段宽度:
转换字符:
注释:如果使用多个上述的格式值,它们必须按照上面的顺序进行使用,不能打乱。 注释:该函数受本地设置的影响。 |
number | 必需。被插入到格式化字符串中 % 符号位置的数字。 |
technical details
return value: | Returns the formatted string. Format strings preceding and following characters will remain the same return. Non-numeric digit returns NULL and generate E_WARNING. |
---|---|
PHP version: | 4.3.0+ |
More examples
Example 1
International format with two small number (Germany):
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>
The code above will output:
Example 2
Negative with () indicates a negative US international format right precision is 2, "*" is filled with characters:
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>
The code above will output: