php - Converting a number with comma as decimal point to float -
i have list of prices comma decimal point , dot thousand separator.
some examples:
12,30
116,10
1.563,14
these come in format third party. want convert them floats , add them together.
what best way this? number_format doesn't seem work format, , str_replace seems overkill, have more once on each number.
is there better way? thanks.
using str_replace()
remove dots not overkill.
$string_number = '1.512.523,55'; // note: don't have use floatval() here, it's prove it's legitimate float value. $number = floatval(str_replace(',', '.', str_replace('.', '', $string_number))); // @ point, $number "natural" float. print $number;
this least cpu-intensive way can this, , odds if use fancy function it, under hood.
Comments
Post a Comment