This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

parseInt

Summary

Converts a string to an integer.

Syntax

parseInt( numString , [ radix ])
numString
Required. A string to convert into a number.
radix
Optional. A value between 2 and 36 that specifies the base of the number in numString. If this argument is not supplied, strings with a prefix of ‘0x’ are considered hexadecimal. All other strings are considered decimal.

Examples

parseInt("123.45");  // returns 123
parseInt("abc");  // returns NaN
parseInt("12abc");  // returns 12

Remarks

The parseInt function returns an integer value equal to the number contained in numString. If no prefix of numString can be successfully parsed into an integer, NaN (not a number) is returned.

You can test for NaN using the isNaN function.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article