javascript" parseInt()" [英] Problems with javascript "parseInt()"

查看:116
本文介绍了javascript" parseInt()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

JavaScript parseInt八进制bug的变通办法

如何解析带前导0的字符串





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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆