1

I would like to convert a hex number to decimal.

2

1 Answer 1

-1

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]

5
  • The question explicitly asks how to do it in solidity.
    – Ismael
    Feb 16 at 6:35
  • That's Solidity - if you don't know.
    – Ololade
    Feb 16 at 9:34
  • This isn't solidity const { utils, BigNumber } = require("ethers").
    – Ismael
    Feb 16 at 18:56
  • Run it in a solidity environment and see if it will run or throw an error.
    – Ololade
    Feb 17 at 8:04
  • It errors out in Remix ParserError: Expected identifier but got '{'.
    – Ismael
    Feb 17 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.