Possible unintended behavior when converting FixedNumber to BigNumber #2553
Replies: 4 comments 1 reply
-
Is this intended behavior? If it is, what would be the correct way to convert a FixedNumber to a BigNumber? |
Beta Was this translation helpful? Give feedback.
-
The By default the decimals component is 0, which means the value passed in is the whole component. If you are trying to reposition the decimal point with respect to the value, you need to specify your own decimals offset. See here: https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/fixednumber.ts#L328 |
Beta Was this translation helpful? Give feedback.
-
Perhaps I was unclear:
Easier to see here:
|
Beta Was this translation helpful? Give feedback.
-
I did some digging, when calling This is the line: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Using BigNumber.from() on a FixedNumber ignores the comma, treats the whole number and decimals as an int. This can cause issues, for example passing a FixedNumber in a contract call will internally convert it to BigNumber, resulting in the contract being called with a much larger value than intended.
Reproduction steps
Environment:
Latest Node.js Docker image
Search Terms
BigNumber, FixedNumber, decimal, conversion
Beta Was this translation helpful? Give feedback.
All reactions