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
fix: precision leaves 1000 kB in the old unit and rounds to round before the unit bump #413
Two problems in the precision path when the value moves to the next unit (applyPrecisionHandling):
Since 11.0.31 (fix: apply precision before round for decimal units #404), a value that rounds up to the unit ceiling stays in the old unit: filesize(999999, { precision: 4 }) prints 1000 kB, while filesize(999999) prints 1 MB. 11.0.30 printed 1.000 MB. The unit only moves when toPrecision() returns e-notation, and (999.999).toPrecision(4) is "1000".
When the unit does move, the new value is rounded to round decimals before toPrecision() runs. This is the same double rounding fix: precision is applied after round, rounding an already-rounded value #399 fixed in the main path. With round: 0 it even prints 0: filesize(392, { precision: 1, round: 0 }) gives 0 kB.
In applyPrecisionHandling() (src/helpers.js) the bump runs only on result.includes(E), and the recomputed value goes through roundingFunc(valueResult * p) / p before toPrecision(). The existing test "should handle precision with specific test case for GiB values" pins 0.990 GiB, but 1058223158 / 2^30 = 0.98555. I have a fix ready and will open a PR.
Activity