Javascript zero paddedstring to int [duplicate]
Possible Duplicate:
Workarounds for JavaScript parseInt octal bug
I have the following numbers:
01 02 03 04 05 06 07 08 09 10 11 12
These are a string I want to convert them to an int. So 02 becomes 2. I have parseInt('02')
but this returns int 0
Include the radix: parseInt('02', 10)
You need to tell javascript the type of number you're trying to convert.
parseInt('02', 10); // number is base 10
See this question for more details.
精彩评论