Web Analytics Made Easy -
StatCounter strange problem with parseInt - CodingForum

Announcement

Collapse
No announcement yet.

strange problem with parseInt

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • strange problem with parseInt

    Code:
    I am having a wierd problem.  I pass a 2 digit numeric month value (ie 01-12) to the below function.  It works as expected for 01-07 and 10-12 but for some reason if 08 or 09 is entered it thinks it isnt an integer!
    
    function isInteger(value) {
      return (parseInt(value) == value);
    }
    I am completely baffled by this, so any help would be much appreciated!

    Andy.

  • #2
    If you put a 0 in front of the number it will be interpreted as an octal number. Send a second argument, 10, to the parseInt function. This will override this automatic radix determination.
    liorean <[[email protected]]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

    Comment


    • #3
      Try

      return (value = parseInt(value));
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        Originally posted by liorean
        If you put a 0 in front of the number it will be interpreted as an octal number. Send a second argument, 10, to the parseInt function. This will override this automatic radix determination.
        Great, thanks - I would never have thought of that!

        Comment

        Working...
        X