Javascript, why treated as octal

If you receive your parameters as string objects, it should work to use

 parseInt(string, 10)

to interpret strings as decimal, even if they are beginning with 0.

In your test, you pass the parseInt method a number, not a string, maybe that’s why it doesn’t return the expected result.


 parseInt('0000022115', 10)

instead of

parseInt(0000022115, 10)

that does return 221115 for me.

Leave a Comment