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

Resolve values with too many decimal places #1069

Merged
merged 8 commits into from
Jun 4, 2024
Merged

Resolve values with too many decimal places #1069

merged 8 commits into from
Jun 4, 2024

Conversation

Jozzey
Copy link
Contributor

@Jozzey Jozzey commented Jun 4, 2024

https://eaflood.atlassian.net/browse/WATER-4489

We have spotted an issue while working on two-part tariff where some of the decimal values calculated didn't quite look as we would have expected them to. After some investigation we found that this is a common issue with JavaScript when adding decimals together. A decent explanation of this issue can be found here https://ellenaua.medium.com/floating-point-errors-in-javascript-node-js-21aadd897bf8

To resolve this problem we are importing a new package that will enable us to perform mathematical functions on decimals without any issues. Several potential packages were evaluated for suitability including decimal.js & bignumber.js but in the end we have settled on big.js as it fits our needs the best and is well used at nearly 2 million downloads a week.

In this PR the package is going to be imported and used on any existing calculations that involve decimals.

https://eaflood.atlassian.net/browse/WATER-4489

We have spotted an issue while working on two-part tariff where some of the decimal values didn't quite look as we would have expected them to. After some investigation we found that this is a common issue with JavaScript when adding decimals together. A decent explanation of this issue can be found here https://ellenaua.medium.com/floating-point-errors-in-javascript-node-js-21aadd897bf8

To resolve this problem we are importing a new package that will enable us to perform mathematical functions on decimals without any issues. Several potential packages were evaluated for suitability including `decimal.js` & `bignumber.js` but in the end we have settled on `big.js` as it fits our needs the best and is well used at nearly 2 million downloads a week.

In this PR the package is going to be imported and used on any existing calculations that involve decimals.
@Jozzey Jozzey added the bug Something isn't working label Jun 4, 2024
@Jozzey Jozzey self-assigned this Jun 4, 2024
@Jozzey Jozzey marked this pull request as ready for review June 4, 2024 15:46
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jozzey Jozzey merged commit d8a1cd4 into main Jun 4, 2024
6 checks passed
@Jozzey Jozzey deleted the fix-decimal-issue branch June 4, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants