I've got some strings that I need to cast as floats but have seen two apparently different ways of doing it:
$float = floatval ($float);
and
$float = (float) $float;
Are there any differences between the two methods?
I've got some strings that I need to cast as floats but have seen two apparently different ways of doing it:
$float = floatval ($float);
and
$float = (float) $float;
Are there any differences between the two methods?
In all other cases it will be evaluated as a float. In other words, the $string is first interpreted as INT, which cause overflow (The $string value 2968789218 exceeds the maximum value ( PHP_INT_MAX ) of 32-bit PHP, which is 2147483647.), then evaluated to float by (float) or floatval()
Please have look at PHP Convert String into Float/Double
The best answer for this is Typecasting vs function to convert variable type in PHP