I am trying to find a percentage using the Big Number library from @openzeppelin/test-helpers
Here is the code:
var someVarABC = new BN('2706'); var someVarDEF = new BN('5060584'); var total = someVarABC.add(someVarDEF); var percentage = (someVarDef.div(total)).mul(new BN('100'));
The error I get is:
Error: Assertion failed at assert (node_modules/web3-utils/node_modules/bn.js/lib/bn.js:6:21) at BN.divmod (node_modules/web3-utils/node_modules/bn.js/lib/bn.js:2329:5) at BN.div (node_modules/web3-utils/node_modules/bn.js/lib/bn.js:2425:17) at Context.<anonymous> (test/ERC20/SomeToken.test.js:84:48) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:94:5)
I know the problem is the division part where the result is .99 before multiplying by 100 but how can I work around this? I think on the solidity side there wouldn’t be an issue because fractional numbers are usable during calculations but just not to store in variables which is something I can work with but how do I fix the truffle test?