I have this number
float(1.3098140391E+17)
number_format does not output an exact one...
How can I have the exact integer?
float number to integer
Moderator: General Moderators
Re: float number to integer
At least to a string... do not need an integer.
Value comes from an API query and need the exact number for future queries to the API server.
Value comes from an API query and need the exact number for future queries to the API server.
Re: float number to integer
Just figure it is json_decode function which is converting the number to a float...
array(1) { [0]=> object(stdClass)#1 (5) { ["id"]=> float(1.3098892990102E+17) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) } }
How can I get the $string->id = 130988929901015042 ?
Code: Select all
$string = '[{"id":130988929901015042,"b":2,"c":3,"d":4,"e":5}]';
var_dump(json_decode($string));array(1) { [0]=> object(stdClass)#1 (5) { ["id"]=> float(1.3098892990102E+17) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) } }
How can I get the $string->id = 130988929901015042 ?
Re: float number to integer
Code: Select all
$string = '[{"id":130988929901015042,"b":2,"c":3,"d":4,"e":5}]';
$string = preg_replace( '/id":(\d+)/', 'id":"\1"', $string );
$array = json_decode($string);
echo $array[0]->id;