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 »
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.
If the first character cannot be converted, NaN
is returned.
Leading and trailing spaces are ignored.
Only the first integer found is returned.
Number.parseInt(
string, radix)
Parameter | Description |
value | Required. The value to be parsed. |
radix | Optional. Default is 10. A number (2 to 36) specifying the number system. |
Type | Description |
Number | NaN if no integer is found. |
Number.parseInt()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Number.parseInt()
is not supported in Internet Explorer 11 (or earlier).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!