This has happens when I convert a large number to string in Javascript, it seems to give me a result which i do not expect:
var x=1234567890123456;
console.log(x) //1234567890123456 –equal…
console.log(x.toString()) //1234567890123456 –equal…
var x=12345678901234567;
console.log(x) // 12345678901234568 –different!
console.log(x.toString()) //12345678901234568 –different!
var x=123456789012345678;
console.log(x) //123456789012345680 –different!
console.log(x.toString()) //123456789012345680 –different!
console.log(x+””) //123456789012345680 –different!
Can anyone could tell me the reason for this, and how to deal with it?
The reason is the maximum of numbers in javascript (+/- 9007199254740992) without losing precision. Also see this question.