PHP number_format() 将小数 0.99 转换为 0.00
我想把一个“肮脏”的数字变成一个正确书写的货币价格。 输入数字类似于 23.99000,我想显示 23,99 + 欧元符号。
我使用这个:
$price = number_format($price, 2, ',', '')." €";
但结果将是 23,00 € 而不是 23,99 €。
我错了什么?谢谢!
I want to turn a "dirty" figure into a properly written currency price.
The input figure will be something like 23.99000 and I want to display 23,99 + the Euro symbol.
I use this:
$price = number_format($price, 2, ',', '')." €";
But the result will be 23,00 € instead of 23,99 €.
What am I getting wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试如下操作:
输出:
f
表示它将把字符串视为浮点数,并相应地设置格式。Try something like this:
Output:
the
f
means it'll treat the string as a float, and format accordingly.为什么不简单地使用 round ?
Why not simply using round ?