Closed Bug 307182 Opened 19 years ago Closed 19 years ago

Javascript function parseInt parses "08" and "09" incorrectly

Categories

(Firefox :: General, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 43425

People

(Reporter: heinz.sporn, Unassigned)

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050902 Firefox/1.0.6
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050902 Firefox/1.0.6

The Javascript function parseInt parses some rather simple strings incorrectly.
I just tested the following strings: '01', '02", '03', '04', '05', '06', '07',
'08', '09', '10'. All strings except '08' and '09' are correctly transformed to
their corresponding integer values. But '08' and '09' result in the integer value 0.

Reproducible: Always

Steps to Reproduce:
Try the following test code:

<html>
<head><title>parseInt Test</title>
   <script language="Javascript">
      function fnParseInt() {
         alert ('00='+parseInt('00'));
         alert ('01='+parseInt('01'));
         alert ('02='+parseInt('02'));
         alert ('03='+parseInt('03'));
         alert ('04='+parseInt('04'));
         alert ('05='+parseInt('05'));
         alert ('06='+parseInt('06'));
         alert ('07='+parseInt('07'));
         alert ('08='+parseInt('08'));
         alert ('09='+parseInt('09'));
         alert ('10='+parseInt('10'));
         }
</script>
</head>
<body onload="fnParseInt();">
</body>
</html>
Actual Results:  
Values '08' and '09' result in 0.

Expected Results:  
8 and 9.

Found this misbehaviour both in Firefox for Linux 1.0.6 and Firefox for Windows
1.0.1.

Also it makes no difference using a temp variable to influence type casting like:

var iTemp=0;
iTemp=parseInt('08');
parseInt treats numbers starting with 0 as octal.  The digits "8" and "9" don't
exist in octal, so the number "08" is considered to end before the "8".  If you
want to treat the number as decimal regardless of prefixes, pass parseInt a
second parameter of 10 (e.g. parseInt("08", 10)).

*** This bug has been marked as a duplicate of 43425 ***
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → DUPLICATE
Attached file Testcase as HTML file
Summary: Javascript function parseInt parses incorrectly → Javascript function parseInt parses "08" and "09" incorrectly
Status: RESOLVED → VERIFIED
After consulting the Core Javascript Reference 1.5 I have to admit that
Firefoxes behaviour is 100% following the rules. It seems that browsers like
Opera and IE didn't implement parseInt according to the specs. I should have
looked into the reference first - sorry for the inconvenience.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: