如何在PHP中将数字格式化为美元数量 [英] How do I format a number to a dollar amount in PHP
本文介绍了如何在PHP中将数字格式化为美元数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将数字转换为显示美元和美分的字符串?
例如:
123.45 => ; '$ 123.45'
123.456 => '$ 123.46'
123 => '$ 123.00'
.13 => '$ 0.13'
.1 => '$ 0.10'
0 => '$ 0.00'
解决方案
PHP也有 money_format()。
以下是一个例子:
echo money_format('$%i',3.4); // echos'$ 3.40'
这个函数实际上有很多选项,转到我链接的文档看看他们。
$ b
注意:money_format在Windows中是未定义的。
How do you convert a number to a string showing dollars and cents?
eg:
123.45 => '$123.45'
123.456 => '$123.46'
123 => '$123.00'
.13 => '$0.13'
.1 => '$0.10'
0 => '$0.00'
解决方案
PHP also has money_format().
Here's an example:
echo money_format('$%i', 3.4); // echos '$3.40'
This function actually has tons of options, go to the documentation I linked to to see them.
Note: money_format is undefined in Windows.
这篇关于如何在PHP中将数字格式化为美元数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文