Skip to content
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

missing math function: round-to up/down with precision #1901

Closed
anieve01 opened this issue Jun 30, 2020 · 4 comments
Closed

missing math function: round-to up/down with precision #1901

anieve01 opened this issue Jun 30, 2020 · 4 comments

Comments

@anieve01
Copy link

this math library will be complete if it includes the following math functionality, which is heavily used in financial use cases (e.g., banker's rounding): https://github.com/sindresorhus/round-to

@josdejong
Copy link
Owner

Thanks for your suggestion. Maybe we can extend the existing function floor(x) and ceil(x) to pass a number of digits like round(x, n). Or we could extend round to allow passing rounding options like UP, DOWN, etc.

You can configure to use BigNumber (better anyway to use that for finanical data than regular numbers because regular numbers suffer a lot from round-off errors). The BigNumber library integrated in mathjs is powered by https://github.com/MikeMcl/decimal.js, which allows to configure different rounding options. So you could write a wrapper function to use that I think.

@rnd-debug
Copy link
Contributor

Working on providing floor(x, n) and ceil(x, n). Let's see how it goes.

@josdejong
Copy link
Owner

👍 thanks @rnd-debug !

@josdejong
Copy link
Owner

Available now in v7.4.0, thanks again @rnd-debug .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants