Datatype Conversion to Integer (Javascript):   Return to List

Function: parseInt(string, radix)
The parseInt() method is used to convert a string to an integer.
It can take a string input with an optional radix input.
The radix input represents the base of the number in the string.

Example:
// convert the string "859" to an integer
    var = parseInt("859")
// converts a binary string "101101" to an integer
    var = parseInt("101101", 2)
// converts a hexadecimal string into an integer
    var = parseInt("FA832B", 16)

Function: parseFloat(string)
The parseFloat() method is used to convert a
    string (with numbers & decimals) to a number.
    
Example:
Convert the string "1234.31" to a number
    var = parseFloat("1234.31")



Note to Webmaster