PHP money_format() 函数
PHP 教程
· 2019-01-29 17:44:47
实例
en_US 国际格式:
<?php
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);
?>
$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)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要格式化的字符串及如何格式化字符串中的变量。 可能的格式值: 填充和标志:
字段宽度:
转换字符:
注释:如果使用多个上述的格式值,它们必须按照上面的顺序进行使用,不能打乱。 注释:该函数受本地设置的影响。 |
| number | 必需。被插入到格式化字符串中 % 符号位置的数字。 |
技术细节
| 返回值: | 返回已格式化的字符串。格式化字符串前面和后面的字符将保持不变返回。非数值数字会返回 NULL 并产生 E_WARNING。 |
|---|---|
| PHP 版本: | 4.3.0+ |
更多实例
实例 1
带 2 个小数的国际格式(德国):
<?php
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>
$number = 1234.56;
setlocale(LC_MONETARY,"de_DE");
echo money_format("%.2n", $number);
?>
上面的代码将输出:
1 234,56 EUR
实例 2
负数,带有 () 指示负数的 US 国际格式,右侧精度为 2,"*" 为填充字符:
<?php
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>
$number = -1234.5672;
echo money_format("%=*(#10.2n",$number);
?>
上面的代码将输出:
(******1234.57)
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
Introduction to Computation and Programming Using Python
John V. Guttag / The MIT Press / 2013-7 / USD 25.00
This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
在线进制转换器
各进制数互转换器