Is there any limitation for integer in javascript? [duplicate]
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 123456789开发者_如何学Python01234567890
?>
<script>
var d = <?php echo $data ?>
alert(d); // value here is 12345678901234567000
</script>
Any idea why this happens?
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
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.
精彩评论