The example in this article describes the solution for converting digital objects into scientific notation after using json_decode in PHP. Share it with everyone for your reference. The details are as follows:
Question:
Today I am working on connecting web games to Facebook points, and Facebook sent a class json string, I want to apply these parameters in the callball.php page, so I performed a json_decode operation and found that the long numbers turned into scientific notation, which was not the result I wanted.
Solution:
After various conversion processes, it still doesn’t work:
$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 PHP’s built-in function number_format(), the problem is solved, 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 )
More php uses json_decode to convert the numerical object into scientific notation Please pay attention to the PHP Chinese website for related articles on solutions!