javascript" parseInt()" [英] Problems with javascript "parseInt()"
本文介绍了javascript" parseInt()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
document.write(parseInt("07"));
产生7
document.write(parseInt("08"));
产生0
这是为我产生问题(对不起这个唠叨,我必须或我不能提交问题)。任何人都知道为什么它是愚蠢的或者是否有更好的功能?
This is producing problems for me (sorry for this babble, I have to or I can't submit the question). Anyone know why it's being stupid or if there is a better function?
推荐答案
如果你的参数以0开头,它将被解析作为八进制,08不是有效的八进制数。提供第二个参数 10
,它指定基数 - 基数为10的数字。
If you argument begins with 0, it will be parsed as octal, and 08 is not a valid octal number. Provide a second argument 10
which specifies the radix - a base 10 number.
document.write(parseInt("08", 10));
这篇关于javascript" parseInt()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文