-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add floor and ceiling to FixedNumber #1037
Comments
An important reason why ethers has its own implementation of BigNumber is to be immutable. So no in-place operations are available... It makes things much simpler throughout the async nature of blockchain that capturing a reference is sufficient (also copying is fast; just store a reference) which requires all numbers remain immutable. Sorry. :s |
Is there an equivalent workaround with existing methods? |
Well, you can just re-assign to the original value. :) // equivalent to value.idiv(divisor)
value = value.div(divisor); |
Ah - okay sorry, I was not referring to inplace division, I was referring to integer division: https://mikemcl.github.io/bignumber.js/#divInt |
Oh, I see. That makes more sense. :) The BigNumber class will likely never support that, however, you can use the FixedNumber class to get something similar:
You can also specify the internal fixed format to use, which is by default Does that help? |
bare with me - I am a math noob Is is possible to have a way for specifying if division rounds up or down? |
Oh! That is actually something I’ve been meaning to add, but it hasn’t been a priority. But I can add it this week. I plan to support a bunch of tie-breaking rounding algorithms:
For now I will add floor and ceiling. If there is any other rounding strategy you need though, let me know. |
I've added a Thanks! :) |
This has been published, so I'm going to close it now. If you have any issues though, please re-open. Thanks! :) |
No description provided.
The text was updated successfully, but these errors were encountered: