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.
We have a cell in the example.xlsx sheet containing a total sum as a formula: E1 = IF(SUM(A1:B1) = SUM(C1:D1), "true", "false"), where:
A1 = 1.1,
B1 = 2.7,
C1 = 1.8,
D1 = 2.
We expect the calculation result to be E1 = "true", but instead, we get E1 = "false" because in PHP, the addition yields:
1.1 + 2.7 = 3.8000000000000003,
1.8 + 2 = 3.8.
The idea of the fork is to accept an input parameter specifying the number of decimal places and round the final sum to that precision before comparison.
Additional Notes:
This issue arises due to floating-point precision errors in programming languages like PHP.
A possible solution is to use rounding (e.g., round(SUM(A1:B1), N) == round(SUM(C1:D1), N) where N is the desired decimal precision).
This is: