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