I have this number
float(1.3098140391E+17)

number_format does not output an exact one...
How can I have the exact integer?

    Just figure it is json_decode function which is converting the number to a float...

    $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 ?

      The number is simply too large. You must be running on a 32-bit operating system.

      On a 32-bit system, the largest an integer can be is 2147483647 (just over 2 billion).

      On a 64-bit system, the largest an integer can be is 9223372036854775807 (just over 9 quintillion).

      If an integer is too large, it's handled as a float. You can read the manual on integers for more information.

      EDIT: The only way you're going to be able to "work" with the number in its entirety is to do so as a string.

      $string = '[{"id":"130988929901015042","b":2,"c":3,"d":4,"e":5}]'; //Notice the additional double quotes around the number
      

        Assuming you do not need to use it in a mathematical context but just need to use it as a unique identifier, then using it as a string should be fine. If you do need to do any math with it, you may need to use something like the [man]BCMath[/man] or [man]GMP[/man] functions (where you still have to express the number as a string, but it can then be operated upon arithmetically).

          Write a Reply...