如何将所有非数字字符交换为货币格式
我需要有人帮助,我将不胜感激,非常感谢
下面是左侧我想交换为货币格式/右侧的几个示例
- 123,00 至 123.00
- 1.123,00€ 至 1,123.00
- $11.123,00 至 11,123.00
- 12.123,00 ZH至 12,123.00
- 12.123,00cH 至 12,123.00
- £1.123.123,00 至 1,123,123.00
- 112312300 KN 至 1,123,123.00
或例如
- 1,123.00€ 至 1,123.00
- $11.123.00 至11,123.00
- 12,123,00 ZH 至 12,123.00
- 12.123,00cH 至 12,123.00
- £1.123,123,00 至 1,123,123.00
- 11,231230.0 KN 至 1,123,123.00
这意味着左侧的任何内容应该更改为逗号作为千位数字和点作为十进制数字,
似乎可以使用 preg_replace 或 str_replace 来完成,但我应该做什么?
I need somebody help, I Would be appreciate it and many thanks
Below as several samples that left side i want to swap to currency format/right side
- 123,00 to 123.00
- 1.123,00€ to 1,123.00
- $11.123,00 to 11,123.00
- 12.123,00 ZH to 12,123.00
- 12.123,00cH to 12,123.00
- £1.123.123,00 to 1,123,123.00
- 112312300 KN to 1,123,123.00
or e.g.
- 1,123.00€ to 1,123.00
- $11.123.00 to 11,123.00
- 12,123,00 ZH to 12,123.00
- 12.123,00cH to 12,123.00
- £1.123,123,00 to 1,123,123.00
- 11,231230.0 KN to 1,123,123.00
that mean whatever in left side it should be change to comma as thousand digit and dot as decimal digit,
it seem could be done using preg_replace or str_replace, but what I should do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
去掉非数字字符,然后通过
number_format()
。编辑添加了
/ 100
,因为它在原始零之后添加了小数位。Srip out non-numeric characters, and then pass through
number_format()
.EDIT added
/ 100
since it was adding the decimal places after the original zeros.最简单的方法是首先删除所有非数字内容,然后使用 <代码>数字格式。
The easiest way to do this would be to first remove everything non-numeric and then use
number_format
.你可以尝试
You could try
我必须对货币做同样的事情来规范我正在处理的项目的格式。
如果格式为
#####.##
并支持这些输入,代码将重新处理要输出的任何字符串:以及与任何非数字字符的任何其他组合交错
最后使用
number_format()
重新格式化标准化数字I have had to do the same from currency to normalize the format for a project i'm working on.
The code is reworking any string to output if formatted as
#####.##
and support these inputs :and any other combination interlace with any non numeric chars
And finally use
number_format()
to reformat the standardized number