回声很大 [英] Echo a very large number
问题描述
我有一个不寻常的问题,我不知道如何解决.
I have a unusual problem which I have no idea how to solve.
我有一个JSON文件,其中存储了一个应用程序ID,即以下内容:
I have a JSON file, where a application id is stored, namely the following:
"app_id": "363924477024846"
我从硬盘读取了JSON文件,并使用json_decode()对其进行了解析,以便在我的应用程序中使用它. 但是,在某一时刻,我想将app-id发送到浏览器.问题是,如果我将该变量回显,则其打印如下:
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
有什么办法可以防止这种情况发生?我不需要它被PHP威胁为数字,因为我不对其进行任何计算-一个字符串就可以了.但是由于它仅由数字表示,因此json_decode()似乎将其威胁为数字,即使在这种情况下我很难用引号引起来(应该指出一个字符串),或者在这种情况下PHP只是会执行愚蠢的类型提示,所以我不这样做知道...
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?
推荐答案
我在这里遇到了同样的问题:只需使用phps number_format函数即可解决此问题:
I had the same problem here: Simply use phps number_format function, which solves this issue:
$number = "363924477024846";
echo number_format($number, 0, '', '');
// 363924477024846
这篇关于回声很大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!