21
Apr
2005

Wondering why parseInt( “08″ ) returns 0, in Javascript?

Categories: Software

Well it looks like JS is defaulting to base 8 in it’s parseInt routine. There are 2 workarounds that I’ve come across (once you get over the initial reaction of what the hell use is base8 in a scripting language):

  1. use parseInt( strExpression, 10 ) .. to force decimal
  2. use Number( strExpression ) .. if you’re doing simple numerics

 

Leave a Reply

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.