-
|
There is a BigNumber 10000 returned in the app and needs to be converted to number. Here are 2 ways to convert:
and 2nd:
The 2nd way of converting is in Ethers document. Why it didn't yield correct number? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
But |
Beta Was this translation helpful? Give feedback.
-
|
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 If you need a normal JavaScript IEEE 754 number, you can use |
Beta Was this translation helpful? Give feedback.
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 theparseInt(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?