Convert big number (hex value) to a string or number

Viewed 38

I got this result from calling to a method in a ERC20 token I have deployed on a testnet.

contract MyToken is ERC20, ReentrancyGuard {}

calling method,

 let value = await ptrToken.balanceOf(wallet.address)

I want to convert the resultant big number to a string or number.

BigNumber { _hex: '0x021e19e0c9bab2400000', _isBigNumber: true }

I have tried the following three ways but, resulted 'undefined' as the output in nodejs.

1) const toEther = (_n) => {
    ethers.utils.formatUnits(_n, 'ether')
}

2) toTokens = (_n) => {
    ethers.utils.formatEther(_n)
}
3) const toEther = (_n) => {
    ethers.utils.formatUnits(_n.toString(), 'ether')
}

Passing the value to _n in both above functions resulted 'undefined'

0 Answers
Related