[英]Convert float number to int or string
I am retrieving a Facebook ID and I am getting a float: 我正在获取一个Facebook ID,并且正在浮动:
float(1.1262850591603E+16)
How could I convert it to int (or string) to use it here? 我如何将其转换为int(或字符串)以在此处使用?
http://graph.facebook.com/ 1.1262850591603E+16 /picture
http://graph.facebook.com/ 1.1262850591603E + 16 / picture
I tried intval function, but it returns a wrong result: 我尝试了intval函数,但是返回了错误的结果:
<?php
intval(1.1262850591603E+16); // returns -1062487752
?>
Thank you! 谢谢!
I found the problem and the solution reading the comments :) 我发现问题和解决方案,阅读评论:)
The problem: I was retrieving data from a webservice via curl and json_encoding the result. 问题:我正在通过curl和json_encoding结果从Web服务检索数据。 At this point, json_encode converts bigints into floats.
此时,json_encode将bigints转换为浮点数。
I solved it passing JSON_BIGINT_AS_STRING argument to json_encode. 我解决了将JSON_BIGINT_AS_STRING参数传递给json_encode的问题。
It's documented in PHP documentation: http://php.net/manual/es/function.json-decode.php 它记录在PHP文档中: http : //php.net/manual/es/function.json-decode.php
您可以使用strval
将其转换为字符串strval
: //php.net/manual/zh/function.strval.php
strval($your_float_variable);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.