I have a number in this format:
3 320,17
And I need to get it like:
3320,17
if I use:
floatval($price)
it only return the number 3 separated by the space.
Any idea how to solve?
I have a number in this format:
3 320,17
And I need to get it like:
3320,17
if I use:
floatval($price)
it only return the number 3 separated by the space.
Any idea how to solve?
This should work for you:
Just replace the space and the comma in your number with str_replace()
echo (float) str_replace([" ", ","], ["", "."], $str);
output:
3320.17
To get your float number now in your expected format just use number_format()
.
$str = "3 320,17";
$floatNumber = (float)str_replace([" ", ","], ["", "."], $str);//Create valid float number
echo number_format($floatNumber, 2, ",", "");