Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    525
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Very basic javascript question: what is parseInt used for?

    I would like to know what parseInt means and what type of things it is used for. I see it quite a bit and have researched but do not know what it means... If someone could help me out I would be very grateful. I'm trying to expand my javascript vocabulary lol.
    Single Paradox
    My Site (Under construction)

    Not too bad for a 15 year old

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    See Liorean's post here

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    525
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks bass! helped a lot
    Single Paradox
    My Site (Under construction)

    Not too bad for a 15 year old

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    a small addenda:

    as Liorean said, parseInt() autodetects the hexa and octa numbers, so that it does not always return the values as they were in decimal base. A lot of people forget that parseInt() may be used along with it's parameter base.

    parseInt(string,base)

    So that, to be sure that parseInt('0112') will return 112 as we could expect in decimal, you must specify that the base is 10, otherwise it will return 74

    parseInt('0112',10) //will return 112
    parseInt('0112') //will return 74

    You may see now that parseInt(variable,base) can be used as well for number translation from any base to the decimal base

    for instance:
    parseInt('ff',16) // will translate the hexa number 'ff' into it's decimal equivalent 255
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •