0

Possible Duplicate:
What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?

Hi, I am assigning a php value(obtained from POST) to a javascript variable. When I alert this value,only 17 digits appear. Rest are replaced by 0. However when I echo the post it is fine. The code is below:

<?php
$data = $_POST['data'];  // value here is 12345678901234567890
?>
<script>
var d = <?php echo $data ?>
alert(d);  // value here is 12345678901234567000
</script>

Any idea why this happens?

Community
  • 1
  • 1
Sangam254
  • 3,415
  • 11
  • 33
  • 43

2 Answers2

0

Here is the complete Javascript number reference;

http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference

From within the reference you can see that type integer is accurate to 15 digits.

Brian Scott
  • 9,221
  • 6
  • 47
  • 68
0

From the Mozilla Docs

The MAX_VALUE property has a value of approximately 1.79E+308. Values larger than MAX_VALUE are represented as "Infinity".

See an example here

Swaff
  • 13,548
  • 4
  • 26
  • 26
  • That's the maximum real value, but because all integers in JavaScript are represented as 64-bit doubles, the maximum integer value you can store is 9007199254740992. The maximum safe integer value you should store is 9007199254740991, which is 2^53-1. What you're looking for is Number.MAX_SAFE_INTEGER. – John Kurlak Jul 24 '15 at 15:17