PHP格式化数字,35应该是3500
我正在使用货币,有些商品的价格为 35 美元,有些商品的价格为 35.50 美元,等等。我想将这些数字格式化为“3500”,如果是 35.50,则应该是 3550。
我已经尝试过了
number_format($data['amount'], 2, '', '')
,但如果是 35.50,那就是 355000。
任何帮助都会很棒,谢谢!
I'm working with currencies and there are some items that cost say $35, some that are $35.50, etc. I'd like to take these numbers and format them to '3500' and if it's 35.50, it should be 3550.
I've tried
number_format($data['amount'], 2, '', '')
But if it's 35.50 it's 355000.
Any help would be great, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过将数字乘以 100?
Did you try to multiply the number by 100?
想想你的数学课:
Think of your math lessons:
查看 doc,然后尝试以下操作:
使用最后两个
''
您将小数分隔符替换为空,千位分隔符替换为空,我不认为您打算这样做。更新
我从下面的评论中看到我误解了你的问题。
我在这里用演示尝试了您的代码: http://codepad.org/uNAd84gG
它似乎处于工作状态。
look at the doc, then try this:
with those last two
''
you were replacing the decimal separator with nothing and the thousands separator with nothing, which is something i don't believe you intended to do.update
i see from the comments below that i misread your question.
I tried your code with demo here: http://codepad.org/uNAd84gG
and it seems to be in working order.
尝试:
您可以省略最后 2 个,让它按照您的语言环境运行
try:
You can omit the last 2 to just have it behave by your locale