JavaScript Number.parseInt()
Examples
Number.parseInt("10");
Number.parseInt("10.00");
Number.parseInt("10.33");
Number.parseInt("34 45 66");
Number.parseInt(" 60 ");
Number.parseInt("40 years");
Number.parseInt("He was 40");
Try it Yourself »
Number.parseInt("10", 10);
Number.parseInt("010");
Number.parseInt("10", 8);
Number.parseInt("0x10");
Number.parseInt("10", 16);
Try it Yourself »
Description
The Number.parseInt
method parses a value as a string and returns the first integer.
A radix parameter specifies the number system to use:
2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal.
If radix is omitted, JavaScript assumes radix 10. If the value begins with "0x", JavaScript assumes radix 16.
Notes
If the first character cannot be converted, NaN
is returned.
Leading and trailing spaces are ignored.
Only the first integer found is returned.
Syntax
Number.parseInt(string, radix)
Parameters
Parameter | Description |
value | Required. The value to be parsed. |
radix | Optional. Default is 10. A number (2 to 36) specifying the number system. |
Return Value
Type | Description |
Number | NaN if no integer is found. |
Browser Support
Number.parseInt()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
Number.parseInt()
is not supported in Internet Explorer.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.