How to use parseInt In Javascript
In JavaScript parseInt is a function used to convert a string to an integer. It takes a string argument, like “123“, and returns the integer representation, which ignores leading whitespaces and stops at the first non-numeric character.
Syntax:
parseInt(string, radix);
Example: The below example uses parseInt to perform String to Long Conversion.
let str = "12345678901234567890";
let res = parseInt(str);
console.log(res);
Output
12345678901234567000
JavaScript Program for String to Long Conversion
In JavaScript, there is no specific data type called “Long”, but it uses the “Number” to represent the integer values. We can indirectly convert the String to Long by converting them to Number.
There are several approaches in Javascript to convert strings to long which are as follows:
Table of Content
- Using parseInt
- Using Number
- Using parseFloat
- Using BigInt
- Using Unary Plus (+)