English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article describes the solution to the problem of converting the number object to scientific notation after using json_decode in php. Shared for everyone's reference, as follows:
Problem:
Today I was dealing with the integration of webpage game scores on Facebook, and Facebook passed a class JSON string. I wanted to apply these parameters to the callball.php page, so I performed a json_decode operation, only to find that the long numbers had all become in scientific notation, which was not the result I wanted.
Solution:
All kinds of conversion treatments did not work well:
$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, using the php built-in function number_format(), the problem was solved, and 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 practical json online tools recommended for everyone's reference and use:
Online JSON code inspection, inspection, beautification, and formatting tool:
http://tools.jb51.net/code/json
JSON Online Formatting Tool:
http://tools.jb51.net/code/jsonformat
Online XML/JSON Interconversion Tool:
http://tools.jb51.net/code/xmljson
Online JSON code formatting/Beautify/Compress/Edit/Conversion Tool:
http://tools.jb51.net/code/jsoncodeformat
C Language Style/HTML/CSS/JSON code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json
Readers who are interested in more PHP-related content can check out the special topics on this site: 'PHP json format data operation skills summary', 'PHP mathematical operation skills summary', 'PHP basic syntax tutorial', 'PHP array (Array) operation skills大全', 'PHP string (string) usage summary', 'php+MySQL Database Operation Tutorial and PHP Common Database Operation Skills Summary
I hope this article will be helpful to everyone in PHP program design.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report any violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.