PHP uses Json_decode to convert digital objects into a scientific method of counting

Source: Internet
Author: User
In this paper, we describe the solution of the conversion of the digital object to scientific counting method after PHP using Json_decode. Share to everyone for your reference, as follows:

Problem:

Today in the Web game on Facebook points docking, Facebook passed a class JSON string, want to apply these parameters in the callball.php page, so a json_decode operation, found that the long numbers have become scientific counting method, This is not the result I want.

Workaround:

Do all aspects of the conversion process is not good to make:

$obj = ' {"order_id": 213477815351175, "buyer": 100001169269154} '; $obj = $this->json_decode ($obj, TRUE);p Rint_r ($obj );

Results:

Array (  [order_id] + 2.1347781535118E+14  [buyer] = 1.0000116926915E+14)

Finally, using PHP's own function Number_format (), the problem is resolved , the effect is as follows:

$obj = ' {"order_id": 213477815351175, "buyer": 100001169269154} '; $obj = $this->json_decode ($obj, TRUE); foreach ($obj As $key = $val) {    $obj [$key]=number_format ($val, 0, ', ');} Print_r ($obj);

Results:

Array (  [order_id] = 213477815351175  [buyer] = 100001169269154)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.