为什么parseInt('08')给出0,而parseInt('07')给出7 [英] why parseInt('08') is giving 0, whereas parseInt('07') is giving 7
问题描述
我是在javascript上工作,我似乎发现这很奇怪,javascript函数parseInt('08')返回0而parseInt('07')返回7。
I am working on javascript, and I seem to find this strange, that the javascript function parseInt('08') is returning 0 and parseInt('07') is returning 7.
这种行为似乎存在于Firefox中。
this behavior seems to be there in Firefox.
parseInt('08')在IE中返回8,但在Firefox中返回0 ..
parseInt('08') is returning 8 in IE, but 0 in Firefox..
为什么?我希望parseInt('08')按预期返回8并进入IE。
Why? I want parseInt('08') to return 8, as expected and getting in IE.
推荐答案
是的,我遇到过这个一个之前。这真的很奇怪,因为有些浏览器会将其解释为您希望在基数8中解析它。请考虑以下文章:
Yeah, I came across this one before. It is really odd because some browsers interpret this as you wanting to parse it in base 8. Consider the following article:
http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604
基本上,你必须告诉解析器使用10号基数:
basically, you have to tell the parser to use base 10 numbers:
parseInt('08', '10');
这篇关于为什么parseInt('08')给出0,而parseInt('07')给出7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!