parseInt() method : Type Conversion : Number Data Type JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Number Data Type » Type Conversion »

 

parseInt() method















The parseInt() method starts with the character in position 0 and determines if this is a valid number

If it isn't, the method returns NaN and doesn't continue.

If it is valid, the method goes on to the character in position 1.

This process continues until a character isn't a valid number.

parseInt() takes the string up to that point and converts it into a number.

parseInt("1234AAA") returns 1234 because it stops processing one it reaches the character A.

Any number literal contained in a string is also converted correctly.

The string "0xA" is properly converted into the number 10.

The string "22.5" will be converted to 22, because the decimal point is an invalid character for an integer.








var iNum1 = parseInt("1234blue");
var iNum2 = parseInt("0xA");
var iNum3 = parseInt("22.5");
var iNum4 = parseInt("blue");







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Number Data Type
» Type Conversion