I am using ethers.js I can't figure out how do you convert a bignumber like 1252500000000000000 to 125.25
-Mike
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI am using ethers.js I can't figure out how do you convert a bignumber like 1252500000000000000 to 125.25
-Mike
I was able to use ethers.utils.formatEther( value ) ⇒ string
to convert back to readable.
ethers.utils.formatUnits(value, 6)
. formatEther
is a shorthand for formatUnits(value, 18)
.
Jun 10, 2021 at 12:53
512
in the etherscan. 0.000000000000000512
Math.round(parseFloat(str) * (10 ** 18))
const BigNumber = require('bignumber.js');
let num=new BigNumber(1252500000000000000)
let denom = new BigNumber(10).pow(16)
let ans = num.dividedBy(denom).toNumber()
console.log(ans)
Hope this explains your question.For further info,refer https://mikemcl.github.io/bignumber.js/