开发者

Javascript zero paddedstring to int [duplicate]

开发者 https://www.devze.com 2023-03-12 00:24 出处:网络
This question already has answers here: Closed开发者_如何转开发 11 years ago. Possible Duplicate:
This question already has answers here: Closed开发者_如何转开发 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消