The parseInt() method parses a value by converting it to a string and returns the first integer found. It also accepts an optional radix parameter that specifies the base of the numeral system.
- Converts a string into an integer value.
- Supports different number systems using the radix parameter.
- Stops parsing when a non-numeric character is encountered.
Syntax
parseInt(Value, radix);
Parameters
- Value: This parameter contains a string that is converted to an integer.
- radix: This parameter represents the radix or base to be used and it is optional.
Return value
- It returns a number and if the first character can't be converted to a number then the function returns NaN.
- It returns a number parsed up to that point where it encounters a character that is not a number in the specified radix(base).
[Example 1]: Using Parsing float value
[Example 2]: Parsing value with given radix