开发者

Is there any limitation for integer in javascript? [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜