Blog

PHP: Convert a number that contains a comma to a valid float

0
1
2
3
4
5
6
//let's assume the following number:
$InitialStringNumber = '1.523,55'; // one thousand five hundred ...
$validNumber = floatval(str_replace(',', '.', str_replace('.', '', $InitialStringNumber)));
// Now you can print the natural float number:.
print $number;
//the result will be: 1523.55

Leave a Reply


*