How to convert token to full token without having any rounding errors.
web3.utils.toBN(6221221111111110001).div(10**18).toFixed()
TypeError: num.isZero is not a function at BN.divmod (node_modules/number-to-bn/node_modules/bn.js/lib/bn.js:2329:17) at BN.div (node_modules/number-to-bn/node_modules/bn.js/lib/bn.js:2425:17) at Promise.all.then () at at process._tickCallback (internal/process/next_tick.js:182:7)
bal=6221221111111110001/ (10**(18))
It also has some precision errors.
Any help is appreciated.
web3.utils.toBN
, notweb3.toBigNumber
. Please clarify your question.bal=balance/ (10**(18))
means nothing to us when we have no idea whatbal
andbalance
are. Please clarify that as well.12345 / 10 ** 15
is a value smaller than 1. If you plan to send it to a contract function, then you'll need to convert it to an integer, which means it's going to be a simple0
. So what exactly are you trying to do here? Also, how on earth is that related tobal=balance/ (10**(18))
at the end of the question?web3.utils.toBN.div
gives you the integer division, do you want a regular division? You do realize that you will not be able to send the result to a contract function, right? In other words, it will be useful only on your offchain (Javascript) side.