Possible Duplicate:
JavaScript function parseInt() doesn't parse numbers with leading 0 correctly
Strange issues when parsing in JS occur.
parseInt("08")
//The result is: 0
parseInt("07")
//The result is: 7
Why is this happening?
Because of the 0 prefix. It tells Javascript the number is Octal, in base-8. 8 isn't a legal octal digit.
Use parseInt("8")
instead, or as @Gumbo so correctly pointed out - parseInt("08", 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With