Skip to content

BigNumber.toString and BigNumber._hex.toString are not the same #1722

Answered by ricmoo
emclab asked this question in Q&A
Discussion options

You must be logged in to vote

Do not use numbers! This will almost guarantee you get rounding errors. See: https://docs.ethers.io/v5/api/utils/bignumber/#BigNumber--notes

Also, you should not access _hex. That is internal. The .toString() returns base-10, so the parseInt(base10, 16) will not do what you want. The .toHexString() returns a hex string. Make sure you check out the docs on the BigNumber.

If you need a normal JavaScript IEEE 754 number, you can use BigNumber.toNumber() which will throw if rounding will occur. But you generally do not need normal JavaScript numbers. What are you trying to do?

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@ricmoo
Comment options

Comment options

You must be logged in to vote
4 replies
@emclab
Comment options

@ricmoo
Comment options

@emclab
Comment options

@ricmoo
Comment options

Answer selected by ricmoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants