Home > Backend Development > PHP Tutorial > Solution to convert digital objects into scientific notation after using json_decode in PHP

Solution to convert digital objects into scientific notation after using json_decode in PHP

高洛峰
Release: 2023-03-05 21:46:01
Original
2319 people have browsed it

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);
Copy after login

Result:

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

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);
Copy after login

Result:

Array
(
  [order_id] => 213477815351175
  [buyer] => 100001169269154
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template