toNumber

.toNumber()

This string will be parsed, and converted into a number, and the result is then returned. If the string is of a whole number, then a whole number is returned. If it is a decimal number, then a decimal value is returned.

If the value looks like a hexadecimal value, such as '0xff', then this will be parsed as a hexadecimal. In that example 255 will be returned (the number value of 0xff).

If the string is invalid, then 'NaN' or 'not a number' is returned.

str = "9393.48"
num = str.toNumber()
console( num ) // outputs 9393.48

See also

toInt