You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: The precisionRounding: 14 causes the =200.05 - 200 equation to print 0.0500000000000114 instead of 0.05 #1300
As in the title, if we use precisionRounding: 14 for the 200.05 - 200 calculation we get 0.0500000000000114 instead of 0.05 value. However, it all works well if we setup the precisionRounding to 10.
It is caused by the (im)precision of the JavaScript floating-point arithmetics. In most programming languages, calculations that involve fractional numbers are never 100% accurate, e.g. the famous case with 0.1 + 0.2 ≠ 0.3.
HyperFormula uses the standard JavaScript implementation of arithmetic operations, which says that 200.05 - 200 = 0.05000000000001137. To make this result more human-friendly, HyperFormula applies rounding according to precisionRounding parameter:
precisionRounding
Rounded result
10
0.05
11
0.05
12
0.05000000000001
13
0.050000000000011
14
0.0500000000000114
15
0.05000000000001137
Currently, our documentation says:
We recommend setting precisionRounding to a value between 10 and 14.
with 14 being the default value.
What can we do?
Change the default value of precisionRounding to 10 or 11 (breaking change)
Change the recommended values of precisionRounding
Explain the rounding issue better in our documentation:
Add Setting precisionRounding too high will expose the floating-point calculation errors (for example, with precisionRounding set to 15, 0.1 + 0.2 results in 0.3000000000000001). to the description of precisionRounding
After discussing it with @evanSe we decided to apply the documentation changes (points 2 and 3) in the scope of this task. Changing the default value of the config parameter (point 1) will be scheduled for the next major release.
Instead of changing the default value, we will expand the reference to describe the js arithmetic issues better and recommend precisionRounding: 10 for most day-to-day use cases.
Activity
sequba commentedon Aug 25, 2023
It is caused by the (im)precision of the JavaScript floating-point arithmetics. In most programming languages, calculations that involve fractional numbers are never 100% accurate, e.g. the famous case with 0.1 + 0.2 ≠ 0.3.
HyperFormula uses the standard JavaScript implementation of arithmetic operations, which says that
200.05 - 200 = 0.05000000000001137. To make this result more human-friendly, HyperFormula applies rounding according to precisionRounding parameter:precisionRounding0.050.050.050000000000010.0500000000000110.05000000000001140.05000000000001137Currently, our documentation says:
with
14being the default value.What can we do?
precisionRoundingto10or11(breaking change)precisionRoundingSetting precisionRounding too high will expose the floating-point calculation errors (for example, with precisionRounding set to 15, 0.1 + 0.2 results in 0.3000000000000001).to the description ofprecisionRoundingsequba commentedon Sep 14, 2023
After discussing it with @evanSe we decided to apply the documentation changes (points 2 and 3) in the scope of this task. Changing the default value of the config parameter (point 1) will be scheduled for the next major release.
evanSe commentedon Apr 4, 2024
Changed my opinion on this, changing
precisionRoundingdefault value to something less than 14 causes more issues than it solves.sequba commentedon Apr 4, 2024
Instead of changing the default value, we will expand the reference to describe the js arithmetic issues better and recommend
precisionRounding: 10for most day-to-day use cases.sequba commentedon Nov 6, 2024
During the internal discussion (https://handsoncode.slack.com/archives/C031GBX62SE/p1721909912700709) we decided, that we WILL change the default value to 10.
AMBudnik commentedon Jan 14, 2025
Closed as released in HyperFormula
v3.0.0. Reference: https://hyperformula.handsontable.com/guide/release-notes.html#_3-0-0. Thank you @sequba !