I can calculate for example
x = 0.28
y = 1e18
x * y = 280,000,000,000,000,000
How can I do this in javascript while x could be any number, including ints, and y could be any other big number like 1e12 or whatever.
I can calculate for example
x = 0.28
y = 1e18
x * y = 280,000,000,000,000,000
How can I do this in javascript while x could be any number, including ints, and y could be any other big number like 1e12 or whatever.
You can't mix BigInt with other types in a calculation, so you need to use BigInt for all the operands.
So instead of multiplying the float by 0.28, multiply by 28n and divide by 100n.
console.log((BigInt(1e18) * 28n) / 100n)
28 and you do the division by 100 in your code..285, use BigInt(Math.round(input*1000)) to convert it, then divide by 1000n.
BigIntcannot be mixed with other types. What is the result you expect?