用PHP解析时不格式化资金 [英] Unformat money when parsing in PHP

查看:74
本文介绍了用PHP解析时不格式化资金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法来获取像75,25 €这样的字符串的浮点值,而不是parsefloat(str_replace(',', '.', $var))?

Is there a way to get the float value of a string like this: 75,25 €, other than parsefloat(str_replace(',', '.', $var))?

我希望这取决于当前的网站语言,有时逗号可以用点代替.

I want this to be dependent on the current site language, and sometimes the comma could be replaced by dot.

推荐答案

您可以使用

手册中的示例:

$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
var_dump($formatter->parseCurrency("75,25 €", $curr));

给予:float(75.25)

请注意,默认情况下未启用 intl扩展.请参考安装说明.

Note that the intl extension is not enabled by default. Please refer to the Installation Instructions.

这篇关于用PHP解析时不格式化资金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆