admin管理员组文章数量:1333159
In my code I am getting an input value (integer variable) more that 16 digit number not able to get correct value.
HTML:
<div><input id="number_id" value="111111111111111111"></div>
Script:
$("#number_id").blur(function(){
var ns = $("#number_id").val();
alert(Number(ns))
});
any one have solution please help me.
/
In my code I am getting an input value (integer variable) more that 16 digit number not able to get correct value.
HTML:
<div><input id="number_id" value="111111111111111111"></div>
Script:
$("#number_id").blur(function(){
var ns = $("#number_id").val();
alert(Number(ns))
});
any one have solution please help me.
http://jsfiddle/Qntr2/
Share Improve this question edited Feb 5, 2014 at 7:45 Liath 10.2k10 gold badges54 silver badges82 bronze badges asked Feb 5, 2014 at 7:27 MathiMathi 7621 gold badge10 silver badges15 bronze badges2 Answers
Reset to default 6JavaScript uses 64bit floating point numbers exclusively, which means you only get about 16 decimal digits of precision. This is a fundamental limitation of the number type.
You can store the digits as a string instead. If you need to do putations with numbers this big you'll have to use a library that implements arbitrary precision arithmetic.
All number in javascript can be supported up to 9007199254740992, which is 16 digit numbers. If you store more than that, it will be interpreted wrong. (http://www.2ality./2012/07/large-integers.html)
The best way to do is to store it into string. If you want to do some basic things with big integer, you can use this https://github./jtobey/javascript-bignum
本文标签: javascriptHow to get correct integer value if we give more that 16 digit numberStack Overflow
版权声明:本文标题:javascript - How to get correct integer value if we give more that 16 digit number? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351659a2458616.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论