Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a unusual problem which I have no idea how to solve.

I have a JSON file, where a application id is stored, namely the following:

"app_id": "363924477024846"

I read my JSON file from the HDD and parse it with json_decode() to use it in my application. However, at one point, I want to have the app-id sent to the browser. The problem is, if I echo that variable out, its printed as following:

2.7110712626725E+14

Is there any way to prevent this? I don't need it to be threated as a number by PHP since I am not doing any calculations with it - a string would be fine. But since its represented by numbers only, it seems that json_decode() threats it as a number, even tough I put quotes around it (which should indicate a string) or maybe PHP just does stupid type hinting in this case, I don't know...

Any ideas on how to handle that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
458 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had the same problem here: Simply use phps number_format function, which solves this issue:

$number = "363924477024846";
echo number_format($number, 0, '', '');

// 363924477024846

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...