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!