Php converts numeric objects into scientific notation after using json_decode

Source: Internet
Author: User
This article describes how to convert a numeric object into a scientific notation after json_decode is used by php. it involves the skills related to json format data and numerical conversion in php, for more information about how to convert numeric objects into scientific notation after using json_decode in php, see the example in this article. We will share this with you for your reference. The details are as follows:

Problem:

Today, we are engaged in the integration of Web games on facebook points. facebook transfers a json-like string to the callball. when these parameters are applied on the php page, a json_decode operation is performed, and long numbers are converted into scientific notation, which is not the result I want.

Solution:

It is difficult to handle the conversion in all aspects:

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

Result:

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

Finally, use the built-in function number_format () in php to solve the problem. 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);

Result:

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

For more information about how to convert a numeric object into a scientific notation after using json_decode in php, refer to the PHP Chinese website!

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.