javascript - How to get correct integer value if we give more that 16 digit number? - Stack Overflow

In my code I am getting an input value (integer variable) more that 16 digit number not able to get cor

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

JavaScript 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742351660a4427640.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信