How to use BigInt In Javascript
The BigInt in JavaScript is a built-in object and constructor that allows representation of integers with arbitrary precision. It is used for handling large integer values that exceed the safe integer limit of the standard Number type.
Syntax:
BigInt(value);
Example: The below example uses BigInt to perform String to Long Conversion.
let str = "12345678901234567890";
let res = BigInt(str);
console.log(res);
Output
12345678901234567890n
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 (+)