Closed
Bug 217102
Opened 22 years ago
Closed 22 years ago
javascript:parseInt() returns 0 for string "08" and string "09" only
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
INVALID
People
(Reporter: l.guendogdu, Assigned: rogerl)
References
()
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030701
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030701
javascript:parseInt() returns 0 for string "08" and string "09" only
The sample code below makes the alert message pop up every time. I can reproduce
with string values of "08" and "09". But not with other values. This is a
hardcore bug! I need to find a way to workaround this.
Reproducible: Always
Steps to Reproduce:
// JavaScript sanity check:
var stringValue = "08";
var intValue = parseInt(stringValue);
if (intValue != 8)
alert("WHY THE HELL IS THIS RETURNING " + intValue + "?!?!?!?!?!?!?!?!??!");
Actual Results:
intValue is 0 and should be 8.
Expected Results:
it should have returned 8.
For the most funny thing: this also happens with I.E. 6.0 on W2K.
Reporter | ||
Updated•22 years ago
|
Comment 1•22 years ago
|
||
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/toplev.html#1064173
"If the radix is not specified or is specified as 0, JavaScript assumes the
following:
* If the input string begins with "0x", the radix is 16 (hexadecimal).
* If the input string begins with "0", the radix is eight (octal).
* If the input string begins with any other value, the radix is 10 (decimal)."
Change to:
var intValue = parseInt(stringValue,10);
and it'll work.
Invalid.
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•