将浮点数转换为整数或字符串
Convert float number to int or string
我正在检索 Facebook ID,我得到了一个浮点数:
float(1.1262850591603E+16)
如何将其转换为 int(或字符串)以在此处使用?
http://graph.facebook.com/1.1262850591603E+16/picture
我尝试了 intval 函数,但是 returns 结果错误:
<?php
intval(1.1262850591603E+16); // returns -1062487752
?>
谢谢!
您可以使用 strval
- http://php.net/manual/en/function.strval.php
将其转换为字符串
strval($your_float_variable);
我在阅读评论时找到了问题和解决方案:)
问题:我通过 curl 从网络服务检索数据,json_encoding 结果。此时,json_encode 将 bigints 转换为 floats。
我解决了将 JSON_BIGINT_AS_STRING 参数传递给 json_encode 的问题。
它记录在 PHP 文档中:
http://php.net/manual/es/function.json-decode.php
我正在检索 Facebook ID,我得到了一个浮点数:
float(1.1262850591603E+16)
如何将其转换为 int(或字符串)以在此处使用?
http://graph.facebook.com/1.1262850591603E+16/picture
我尝试了 intval 函数,但是 returns 结果错误:
<?php
intval(1.1262850591603E+16); // returns -1062487752
?>
谢谢!
您可以使用 strval
- http://php.net/manual/en/function.strval.php
strval($your_float_variable);
我在阅读评论时找到了问题和解决方案:)
问题:我通过 curl 从网络服务检索数据,json_encoding 结果。此时,json_encode 将 bigints 转换为 floats。
我解决了将 JSON_BIGINT_AS_STRING 参数传递给 json_encode 的问题。
它记录在 PHP 文档中: http://php.net/manual/es/function.json-decode.php