Skip to main content
Inspiring
January 5, 2014
Answered

why does parseInt("008") return 0

  • January 5, 2014
  • 1 reply
  • 597 views

and parseInt("009") returns 0

when parseInt("006") (and below) returns the proper number?

(Or is it something obvious?)

Thanks

This topic has been closed for replies.
Correct answer TᴀW

A prefix of 0 in parseInt makes it think it's an octal (base 8) number.

If you want to force it to "think decimal", do:

parseInt("008", 10);

Ariel

1 reply

TᴀW
TᴀWCorrect answer
Legend
January 5, 2014

A prefix of 0 in parseInt makes it think it's an octal (base 8) number.

If you want to force it to "think decimal", do:

parseInt("008", 10);

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
Inspiring
January 5, 2014

Thanks. Something obvious...