JavaScript Number parseInt() method
- Tsa kudan parseFloat()
- Tsa gaba prototype
- Ciya kasa Manuwar Reference JavaScript Number
Definition and usage
Number.parseInt()
The method parses the value as a string and returns the first integer.
radix The parameter specifies the numerical system to be used:
2 = Binary, 8 = Octal, 10 = Decimal, 16 = Hexadecimal.
If omitted radix, JavaScript assumes a base of 10. If the value starts with "0x", then JavaScript assumes a base of 16.
Note:
If the first character cannot be converted to a number, then return NaN
.
Leading and trailing spaces will be ignored.
Only returns the first integer found.
Instance
Example 1
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");
Example 2
Number.parseInt("10", 10); Number.parseInt("010"); Number.parseInt("10", 8); Number.parseInt("0x10"); Number.parseInt("10", 16);
Syntax
Number.parseInt(string, radix)
Parameter
Parameter | Description |
---|---|
value | Required. The value to be parsed. |
radix |
Optional. Default is 10. Specifies the numerical system of the number (2 to 36). |
Return value
Type | Description |
---|---|
Boolean value | If an integer is not found, then return NaN. |
Browser support
Number.parseInt()
Is ECMAScript6 (ES6) features.
All modern browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
A dace da suka aiki | A dace da suka aiki | A dace da suka aiki | A dace da suka aiki | A dace da suka aiki |
Internet Explorer 11 (tai kai tsawon tsa) ba a dace da suka aiki ba. Number.parseInt()
.
- Tsa kudan parseFloat()
- Tsa gaba prototype
- Ciya kasa Manuwar Reference JavaScript Number