Is there a way to get the float value of a string like this: 75,25 €, other than parsefloat(str_replace(',', '.', $var))?
75,25 €
parsefloat(str_replace(',', '.', $var))
I want this to be dependent on the current site language, and sometimes the comma could be replaced by dot.
You can use
NumberFormatter::parseCurrency
Example from Manual:
$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY); var_dump($formatter->parseCurrency("75,25 €", $curr));
gives: float(75.25)
float(75.25)
Note that the intl extension is not enabled by default. Please refer to the Installation Instructions.
2.1m questions
2.1m answers
60 comments
57.0k users