I am trying to calculate a result and I want that in int.
calculation =>
const amount = 2000 * 10 ** 18
// Result I am Getiing is 2e+21
console.log(amount);
I also tried the calculation in Math.floor(Number()) But still no success. Is there a way so I can make this calculation and get the real output in just numbers (like 2000000000000000000000) I need to pass this in an API and unfortunately that API parameter is int only.
Remark:- I am not looking for a BigInt solution
You can use BigInt.
// given amount comes from a library you have no control over
const amount = 2000 * 10 ** 18;
const bigInt = BigInt(amount);
// BigInt also has a toString utility method
console.log(bigInt.toString()); // 2000000000000000000000
// use BigInt directly when you are in control
const amount = 2000n * 10n ** 18n;
console.log(typeof amount);
console.log(amount.toString()); // 2000000000000000000000