-
-
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
Does BigNumber only support Integers? (answer: yes) #488
Comments
BigNumber is only for integers, it does not support floating-point or fixed-point math. In v5 (public beta soon) there is a FixedPoint object to help with these, but in the meantime, you can use the Keep in mind that floating-point numbers in JavaScript are NOT precise. They cannot be, it is not possible to represent arbitrary precision with a fixed number of bits (i.e. 64 bits) You will need to choose a resolution you wish the result to be accurate to, but you can for example use:
In general though, if you plan to use decimal numbers there will be a lot of consequences you should familiarize yourself with regarding rounding, underflow (completely unrelated to overflow), parsing/formatting and representation. |
Closing this now, but if you have more questions, please feel free to re-open or continue discussion (I monitor closed issues). In v5, there is a |
- non-integer values causes underflow in ethers bignumber type - see ethers-io/ethers.js#488
Hi everyone,
I have code as below:
in case open = 252350000000000000000000000000000000000, close = 252320000000000000000000000000000000000
const change = ((bigClose.sub(bigOpen)).mul(percentMultiplier)).div(bigOpen) return 0 instead 0.011889663918834626.
So what I do wrong in here? or this is bug? and Do you have any experience or solution for this issue?
Thank you!
The text was updated successfully, but these errors were encountered: