2

Possible Duplicates:
How to parseInt a string with leading 0
Workarounds for JavaScript parseInt octal bug

How can I parse the "09" into number?

alert(parseInt("09"));

This returns me 0 ..Why is that and how do I fix this?

Community
  • 1
  • 1
Manish Basdeo
  • 5,957
  • 21
  • 67
  • 100
  • see: http://stackoverflow.com/questions/850341/workarounds-for-javascript-parseint-octal-bug (basic gist, give a base to the parseInt function because parsing a string with a leading 0 tells parseInt to treat the number as octal, but 9 (and 8) are invalid octal digits) the linked question also provides at least one additional solution as well as lots of groovy info. :) – shelleybutterfly Aug 18 '11 at 05:36

1 Answers1

4

Specify the base as well:

alert(parseInt("09", 10));  // outputs 9
Sarfraz
  • 367,681
  • 72
  • 526
  • 573