How to use large number in javascript?
Code:
let num1 =123456777867;
let num2 = 5324152355467563;
console.log(num1 *num2); //6.573026946790237e+26
let num3 =123456777867n;
let num4 = 5324152355467563n;
console.log(num3 *num4); //657302694679023748214828121n
output:
6.573026946790237e+26
657302694679023748214828121n
Explanation:
when number are large there result is aproximated by default
you can use n at end to declare it as bigint,bigint can store
large number,if n is at end of number then it is bigint datatype.
No comments:
Post a Comment