How to get only the _Hex Value

600 views Asked by At

I have a project in react.js

The next code

console.log(ethers.utils.parseEther('100'.toString()))

Give me the next result in the console

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

I want only giveme the hex value 0x056bc75e2d63100000

i try use '100'.toHexString() but giveme the next error

Unhandled Runtime Error
TypeError: '100'.toHexString is not a function
1

There are 1 answers

2
Byron Mh On

If your value is a number, you can cast it as a hex string with toString method.

const myNumber = 100
const myNumberHexString = myNumber.toString(16) 

If your value is not a number, cast it as one first.