在 PHP 中解析时取消格式化钱 [英] Unformat money when parsing in PHP

查看:24
本文介绍了在 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天全站免登陆