1

When I JSON decoded the JSON in my php one of the numeric value is altered. My JSON is given below:

[
    {
        "__m":"m_0_7p"
    },
   100001572061234,
   null,
   "profile_friends",
   "pb_friends_tl",
   "\/ajax\/add_friend\/action.php",
   "",
   true,
   null,
   false,
   null,
   null,
   "friends_tab",
   []
]

On Json decode the output for the above json is

Array ( [0] => stdClass Object ( [__m] => m_0_7o ) [1] => 1.000091378372E+14 [2] => [3] => profile_friends [4] => pb_friends_tl [5] => /ajax/add_friend/action.php [6] => [7] => 1 [8] => [9] => [10] => [11] => [12] => friends_tab [13] => Array ( ) ) 

where '100001572061234' changed into 1.000091378372E+14. Don't know why this is happening.

5
  • 1
    When PHP displays numbers, it uses the php.ini precision setting to decide whether it should display all digits, or use scientific format..... this is a display setting, it doesn't change the value internally Commented Apr 28, 2015 at 6:59
  • 1
    However, that value is too large for a signed integer in 32-bit PHP, so it will be treated as a float in PHP Commented Apr 28, 2015 at 6:59
  • @MarkBaker thanks. How can this be fixed...... Commented Apr 28, 2015 at 7:02
  • 1
    From PHP 5.4.0 you have an option to use $decoded = json_decode($encoded, false, null, JSON_BIGINT_AS_STRING); - nl1.www.net/manual/en/function.json-decode.php Commented Apr 28, 2015 at 7:04
  • @MarkBaker Thanks for the info. Please post your answer..... Commented Apr 28, 2015 at 7:11

1 Answer 1

2

When PHP displays numbers, it uses the php.ini precision setting to decide whether it should display all digits, or use scientific format..... this is a display setting, it doesn't change the value internally.

However, that value is too large for a signed integer in 32-bit PHP, so it will be treated as a float in PHP

From PHP 5.4.0 you have an option to use the option flags to determine how large integer values are to be handled

$decoded = json_decode($encoded, false, null, JSON_BIGINT_AS_STRING);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.