Unformat money when parsing in PHP
currency, floating-point, parsing, php
Solution
You can use
- `NumberFormatter::parseCurrency` - Parse a currency number
Example from Manual:
$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
var_dump($formatter->parseCurrency("75,25 €", $curr));
gives: `float(75.25)`
Note that the intl extension is not enabled by default. Please refer to the Installation Instructions.
Problem
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.