So I have this for calculating percentage change between two BigNumbers:
const percentageChange = (a: BigNumber, b: BigNumber) => b.sub(a).div(a).mul(BigNumber.from('100'))
Now the issue is when I call toString()
or toNumber()
on it I always get 0
.
The a
and b
are numbers in wei and are very close together, so percentage should be something like 0.000021
or some such.
How do I calculate the percentage and get JS-native type without rounding it to zero?