I would like to convert a hex number to decimal.
1 Answer
Here's how you can do it:
const { utils, BigNumber } = require("ethers);
const largeNumber = BigNumber.from(0x3eef
0f128b45c7eef) // write your hex number inside the bracket
console.log(largeNumber)
console.log(largeNumber.toString()) // if you want to see the bignumber.
You can now take it a step further by converting the bignumber (largeNumber) to decimal like so:
const toDecimal = utils.formatEther(largeNumber);
console.log(toDecimal)
Note Note that ethers version 6 beta has been throwing some errors. Instead, install ether version 5.7.2 - npm install [email protected]