I am using ethers.js I can't figure out how do you convert a bignumber like 1252500000000000000 to 125.25
-Mike
I 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.
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/
For hexadecimal values you can also directly use ethers.utils.formatEther(_hex)
so if the value is 0x3635c9adc5dea00000 ( equals to 1000 * 18**10 ) you can parse it to ether by directly passing it to formatEther
ethers.utils.formatUnits(value, 6).formatEtheris a shorthand forformatUnits(value, 18). – Franco Victorio Jun 10 '21 at 12:53512in the etherscan. 0.000000000000000512 – dcsan Oct 31 '21 at 19:21Math.round(parseFloat(str) * (10 ** 18))– dcsan Oct 31 '21 at 19:22