PHP 将数字转换为货币
我已经仔细寻找了解决我的问题的任何帮助,所以希望有人可以在这里帮助我。
基本上我有一个数字被保存到 $price 中,数字是 15900。这应该转换为 159.00。
有谁知道该怎么做?
I've had a good look around for any help with my problem so hopefully someone can help me here.
Basically i have a number which is saved into a $price, the number is 15900. Which should translate to 159.00.
Does anyone know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,请使用
number_format
。它将返回一个字符串,从而保持小数位不变,即使它们是.00
。或者更好的是,也许也看看
money_format
,具体取决于是否国际化符号和/或货币符号也很重要。Use
number_format
for this. It will return a string, thereby keeping the decimal places intact, even if they will be.00
.Or better still, maybe have a look at
money_format
as well, depending on whether internationalized notations and/or currency symbols are of importance as well.