0

I have a code that sends a long integer from PHP to Javascript.

When I send the 13546000000512023 value, Javascript saves 13546000000512024.

But for other values works.

PHP: 13546000000512022, Javascript: 13546000000512022

PHP: 13546000000512024, Javascript: 13546000000512024

<script>
    function setIdPost(data) {
        console.log(data);
    }
    setIdPost(<?= $_GET["id"]; ?>);
</script>
<?= $_GET["id"]; ?>

It works when I send the value as a string

    setIdPost("<?= $_GET["id"]; ?>");

Why is this happening? I tried in multiple browsers.

I know that these numbers are bigger than Number.MAX_SAFE_INTEGER (9007199254740991). But, Why some of them works and others not?

Pestana
  • 132
  • 1
  • 10
  • The mark as duplicated and the previous comment is about decimals not INTEGERS and no operations are made with this integer – Pestana Feb 09 '23 at 12:41
  • 2
    Numbers in JavaScript are floating points with double precision (IEEE 754). JavaScript doesn't have integers. – jabaa Feb 09 '23 at 12:44
  • This has no relation with PHP per se. Open your browser console, paste in: `console.log(13546000000512023);` and see `13546000000512024`. Also, `console.log(13546000000512025)` gives `13546000000512024`. Fascinating! Must be that `13546000000512024` is some sort of center of gravity for floor and ceil operations. – Markus AO Feb 09 '23 at 16:54

0 Answers0