Skip to content

BigNumber throwing underflow error on 1.49858731, and nothing I do helps #1873

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

You must be logged in to vote

Keep in mind BigNumber is for integers, so it must have 0 decimals.

It looks like you are trying to parse a decimal value into an integer quality, so you probably want ethers.utils.parseUnits(coin.usd_exchange_rate, 8), if it will always be 8 decimals.

If you are trying to later do math with it and maintain its precision, you will need to use the fixed-point math; const value = ethers.FixedNumber.from(coin.usd_exchange_rate), which will by default use fixed128x18 for any operations on it, which should be enough for most peoples purposes.

Does that make sense?

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RichJamo
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