After using json_decode, php converts numeric objects into scientific notation.

Source: Internet
Author: User

After using json_decode, php converts numeric objects into scientific notation.

This article describes how to convert a numeric object into a scientific notation after json_decode is used by php. 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)

PS: Here are some useful json online tools for your reference:

Online JSON code verification, validation, beautification, and formatting tools:
Http://tools.jb51.net/code/json

JSON online formatting tool:
Http://tools.jb51.net/code/jsonformat

Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson

Json code online formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.