Resolve values with too many decimal places #1069
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 onbig.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.