Re: json_decode() and integers larger than LONG_MAX (2^31 - 1)
| From: | Sara Golemon | Date: | Thu, 20 May 2010 21:22:36 +0000 |
| Subject: | Re: json_decode() and integers larger than LONG_MAX (2^31 - 1) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48367@lists.php.net to get a copy of this message | ||
Ilia Alshanetsky wrote:
Could you not treat a very large integer as a double? We do that in a few areas of the code already. Treating it as a double is exactly what json_decode() *currently* does, and it's the problem I'm trying to work around by leaving it in string form.When a large integer is cast as a double, it looses precision, and 1234567890123456789 might suddenly look like (for example) php -r 'var_dump((float)"1234567890123456789" float(1.2345678901235E+18) We've now lost the lowest four digits of this number. For a sum/average/difference type number, that imprecision may be acceptable, but for a specific ID used in (for example) a database, it means that 9,999 of every 10,000 records all wind up correlating to the same incorrect ID. -Sara