I have list of string (size in bytes), I read those from file. Let say one of the string is 2968789218, but when I convert it to float it become 2.00.
This is my code so far :
$string = "2968789218";
$float = (float)$string;
//$float = floatval($string);
//the result is same
// result 2.00
Anyone?
The problem was actually the encoding. It's fine now when I change the file encoding :D
This question is related to
php
string
floating-point
implicit-conversion
If the function floatval does not work you can try to make this :
$string = "2968789218";
$float = $string * 1.0;
echo $float;
But for me all the previous answer worked ( try it in http://writecodeonline.com/php/ ) Maybe the problem is on your server ?
$float = floatval($string);
Try using
$string = "2968789218";
$float = (double)$string;
Source: Stackoverflow.com