parseNumber Function

Top  Previous  Next

Parses a string into a number.

Syntax

parseNumber(string)

Arguments

stringA string to be parsed and converted to a number.

Return Value

The value of the parsed number, or NaN (not a number) if string is not a valid number.

Remarks

Unlike parseFloat and parseInt, parseNumber does not ignore extra characters in string. The entire string must be a valid number, or parseNumber returns NaN. You can test for NaN using isNaN.

Examples

parseNumber("1.5cm")// returns NaN
parseNumber("-12.81")// returns -12.81

See Also

isNaN, parseInt, parseFloat