1

Possible Duplicate:
Workarounds for JavaScript parseInt octal bug

Here's a jsfiddle that shows the behavior:

Pretty simple question, any ideas?

Code is just:

parseInt(013)
Community
  • 1
  • 1
Jake
  • 3,673
  • 8
  • 34
  • 51

3 Answers3

12

Because if your number is starting with '0', then it's considered as octal, thus

'013' = 1 * 8 + 3 = 11
Orabîg
  • 11,475
  • 6
  • 33
  • 54
10

parseInt() expects a string. You have provided an octal, 013.

Use:

parseInt('013', 10)

Note: I would also encourage passing radix, for clarity.

Jason McCreary
  • 69,176
  • 21
  • 125
  • 169
2

The number 013 is being interpreted as an octal. It has nothing to do with parseInt; in fact, var a = 013; will have a be 11.

Ivan
  • 9,534
  • 12
  • 46
  • 78