0

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?

pirs
  • 2,410
  • 2
  • 18
  • 25
dpuscau
  • 11
  • 1
  • 6
    If this is an _id_, you should not treat it as a number, but as a string value. – CBroe May 16 '14 at 19:36
  • If I had to field a guess I'd say that the machines on which you're getting a scientific notation answer are running 32-bit PHP and the Ubuntu machine is running 64-bit. If you're dealing with ID numbers over ~2 billion you should treat them as strings like CBroe suggests for compatibility. – Sammitch May 16 '14 at 19:43

3 Answers3

1

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

stmcallister
  • 1,682
  • 1
  • 12
  • 21
0

You can output the numbers in the same way on all machines using the formatted string functions in PHP, see http://nl1.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);
Dekker1
  • 5,565
  • 25
  • 33
  • @dpuscau note however that the exact number you get out still might be different on different machines. See [this article about floating point math](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) – Jerry May 16 '14 at 19:48
0

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);
Vasyl Lyashkevych
  • 1,920
  • 2
  • 23
  • 38
Jeff
  • 1