Hi there,
I was experimenting with some js code with Math.pow and I found this weird issue.
Here is the code I was using:
And then I did:
Where
When
However, when
Is there a way I can fix this bug/issue?
Thanks,
salm2s
I was experimenting with some js code with Math.pow and I found this weird issue.
Here is the code I was using:
Code:
function convertAmountFormat(amount, invert = false) {
decimals = 8
if (!invert) {
return parseFloat((amount / Math.pow(10, decimals)).toFixed(decimals))
}
else {
return parseInt(amount * Math.pow(10, decimals))
}
}
And then I did:
convertAmountFormat(parseFloat(a) + convertAmountFormat(1000), true)
Where
a
is any positive integerWhen
a
is, for example: 2, It returns:
Code:
convertAmountFormat(parseFloat(2) + convertAmountFormat(1000), true)
= 200001000
However, when
a
is either 4 or 5:
Code:
convertAmountFormat(parseFloat(4) + convertAmountFormat(1000), true)
= 400000999
convertAmountFormat(parseFloat(5) + convertAmountFormat(1000), true)
= 500000999
Is there a way I can fix this bug/issue?
Thanks,
salm2s
Last edited: