| parseInt() The parseInt() method is used to convert a string to a base ten integer. This is useful when wanting to change from a binary to a decimal or hexadecimal (or octal) number. The optional radix number tells the script which number base to use. It should be noted that the string to be converted must begin with a number, or the result will be NaN (Not A Number). If the string starts with numbers then changes to letters, only the numbers will be converted to the integer. It should also be noted that a number that begins with a zero (0) will be treated as an octal (base 8) number. It is a good programming convention to include the base 10 radix number with all of your decimal calculations to avoid any maddeningly strange results from your computations. syntax: parseInt(string) parseInt(string, radix) EXAMPLE document.write("The binary string 1001001, converted to an integer, is " + parseInt('1001001',2) ); This example writes to the screen the words "The binary string 1001001, converted to an integer, is 73". |