Join the Mozilla’s Test Days event from 9–15 Jan to test the new Firefox address bar on Firefox Beta 135 and get a chance to win Mozilla swag vouchers! 🎁

為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

can u help me? why if i use parseInt javascript function for special character number '08' and '09' return is zero for all version firefox...?

  • 5 回覆
  • 2 有這個問題
  • 1 次檢視
  • 最近回覆由 cor-el

more options

var n = '08'; var r = parseInt(n); // r is zero not 8

var n = '08'; var r = parseInt(n); // r is zero not 8

被選擇的解決方法

You need to specify the number base (10).
If not then Firefox might think that it is an octal number and in that case 8 and 9 are invalid.

var n = '08'; var r = parseInt(n,10); // r is 8 
alert(r);
從原來的回覆中察看解決方案 👍 0

所有回覆 (5)

more options

選擇的解決方法

You need to specify the number base (10).
If not then Firefox might think that it is an octal number and in that case 8 and 9 are invalid.

var n = '08'; var r = parseInt(n,10); // r is 8 
alert(r);

由 cor-el 於 修改

more options

thanks for the reply...

can u set default base number in firefox is 10, because other web browser if i parseInt('08') result in 8 n many beginner web developer think parseInt('08') is 8... just a suggestion...

thx again...

more options

No, that is not possible.
The result of parsing an integer with leading zeros can be unpredictable and it is always best to specify the number base anyway to make clear what you mean.

more options

You're welcome.