contents   index   previous   next



global.parseInt()

syntax:

parseInt(str[, radix])

where:

str - to be converted to an integer.

 

radix - the number base to use, default is 10.

 

return:

number - the integer to which string converts, else NaN.

 

description:

This method converts an alphanumeric string to an integer number. The first parameter, str, is the string to be converted, and the second parameter, radix, is an optional number indicating which base to use for the number. If the radix parameter is not supplied, the method defaults to base 10, which is decimal. If the first digit of string is a zero, radix defaults to base 8, which is octal. If the first digit is zero followed by an "x", that is, "0x", radix defaults to base 16, which is hexadecimal.

 

White space characters at the beginning of the string are ignored. The first non-white space character must be either a digit or a minus sign (-). All numeric characters following the string will be read, up to the first non-numeric character, and the result will be converted into a number, expressed in the base specified by the radix variable. All characters including and following the first non-numeric character are ignored. If the string is unable to be converted to a number, the special value NaN is returned.

 

see:

global.parseFloat()

 

example:

var i = parseInt("9");

var i = parseInt("9.3");

// In both cases, i == 9

 


global.setArrayLength()