Reputation: 11
I have installed PHP 5.5 on my laptop, who's running Windows. I'm accessing Smartsheet API, and I supposed to get a column id a number with 18 digits(or sometimes 17). But I get a scientific number:
1.5441916385627E+15
, not 1544191638562692
I ran the script, in a Ubuntu server environment, and I see 1544191638562692. The same, a ran in a OS X Maverick environment, and it's the same the integer format.
I was searching for this matter, and seems to be the precision.
If I'm setting in php, the precision 14 for the OS X Maverick environment like this:
<?php
ini_set('precision', 14);
echo (float)$col->id;
// 1.5441916385627E+15
?>
I get also the scientific number.
Can anybody help me with an idea?
Upvotes: 0
Views: 391
Reputation: 1
One is of possible ways to do it, for example, converting the JSON into an array I had to specify JSON_BIGINT_AS_STRING:
$ColumnsArray = json_decode($data, true,515,JSON_BIGINT_AS_STRING);
Upvotes: 0
Reputation: 1719
As has been mentioned in the comments, this sounds like an issue with running 32-bit PHP. Smartsheet does provide some sample PHP code to help get you started working with the API. In those samples, the documentation recommends that you treat the ids as strings in 32-bit PHP:
https://github.com/smartsheet-platform/samples/tree/master/php/1-HelloSmartsheet#dependencies
Upvotes: 1
Reputation: 5786
You can output the numbers in the same way on all machines using the formatted string functions in PHP, see https://www.php.net/manual/en/function.sprintf.php for the documentation.
So if you would like the integer as a whole you would use:
printf("%u", $number);
Upvotes: 0