Javascript parseInt on large negative number gives NaN

心不动则不痛 提交于 2019-12-12 13:18:32

问题


When I do this:

var x = parseInt("–2147483648");
console.log(x);

I get the value as:

NaN

Why does this happen?

I want to test if a number is in the range of C (int), so I am doing the above, but it does not work. Also, I want to do this for C (long), is there a way to this?

For example: If I do:

var x = parseInt("-9223372036854775808");
console.log(x);

Now, I know that (-+)2^53 is the limit of numbers in Javascript. Is there some other way to test if the given value in a form is actually in the range of long or int?


回答1:


It should work fine, the problem is that you're using the wrong character, an ndash vs a hyphen -:

var x = parseInt("-2147483648");
console.log(x);

If you copy/paste that you'll see that it works now.



来源:https://stackoverflow.com/questions/17825781/javascript-parseint-on-large-negative-number-gives-nan

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!