View Full Version : Very basic javascript question: what is parseInt used for?

Single Paradox
05-27-2005, 01:08 AM
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.

05-27-2005, 01:18 AM
See Liorean's post here (http://www.codingforums.com/showthread.php?t=39075)


Single Paradox
05-27-2005, 01:25 AM
Thanks bass! helped a lot

05-27-2005, 11:55 AM
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.


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