Replies: 5 comments
-
If the maximum number of decimals is allowed is 18, then I think users should not even be allowed to pass anything greater than that to Update: I've just seen this mentioned in the docs:
So this is documented. But I will keep this issue open because there might be a bug on these lines: ethers.js/packages/bignumber/src.ts/fixednumber.ts Lines 335 to 338 in 4166b27 The format that gets created does not take into account the decimals, thus it gets set to 18. Update 2: The bug does not occur if the number has trailing zeros instead of non-zero decimals: const foo = "280000000000000000000000000000000000000000000000000000000000000000000000000000";
const decimals = 77;
const result = FixedNumber.fromValue(foo, decimals);
console.log(result.toString()); // prints 2.8 |
Beta Was this translation helpful? Give feedback.
-
I went around the bug by explicitly setting the format when calling const result = FixedNumber.fromValue(foo, decimals, "fixed256x77"); Mystery solved. When we pass a number of decimals that is larger than 18 and we don't set the format, the |
Beta Was this translation helpful? Give feedback.
-
I think there is some confusion as to what the The The So, the default decimals of So, the value Using a value Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
It does. Thanks a lot for explaining! |
Beta Was this translation helpful? Give feedback.
-
Just discussing this with my partner, and this example came up, which might help explain where the logic and names stem from. const balance = await erc20Contract.getBalance(someAddr);
const decimals = await erc20Contract.decimals();
const value = FixedNumber.fromValue(balance, decimals); Hopefully that helps future peeps who happen across this issue too. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
While working with
FixedNumber
, I got this error after setting the number of decimals to 77:Here's my code:
I then peaked into the guts of the
FixedNumber
implementation, and noticed that the number of decimals gets overridden to 18 in this function:ethers.js/packages/bignumber/src.ts/fixednumber.ts
Lines 342 to 364 in 4166b27
That is, even if it's 77 when it enters the
fromValue
function, it gets set to 18 by the time it is used infromString
.My request is to document the maximum number of decimals that can be set when working with
FixedNumber
, plus any other constraints that there might be.Beta Was this translation helpful? Give feedback.
All reactions