Possible Duplicate:
Workarounds for JavaScript parseInt octal bug
I am trying to parse an integer number.
a = parseInt("0005")  <- gives 5
a = parseInt("0008")  <- gives 0
Can someone explain what's happening? It doesn't make any sense to me.
Possible Duplicate:
Workarounds for JavaScript parseInt octal bug
I am trying to parse an integer number.
a = parseInt("0005")  <- gives 5
a = parseInt("0008")  <- gives 0
Can someone explain what's happening? It doesn't make any sense to me.
 
    
     
    
    When parseInt has a leading 0 and a radix parameter isn't specified, it assumes you want to convert the number to octal.  Instead you should always specify a radix parameter like so:
a = parseInt("0008", 10) // => 8
 
    
    Numbers starting with 0 are parsed as octal by parseInt, unless you specify a radix to use.
You can force parseInt to parse as decimal by doing
a = parseInt("0008", 10)
