Repository navigation
fix: apply precision to the unrounded value to avoid double rounding - #416
Merged
Merged
Conversation
Adds five unit tests covering precision rounding behavior: - 999999 with precision 4 renders as 1.000 MB - 1048575 with base 2 and precision 4 renders as 1.000 MiB - 1024000 with base 2 and precision 3 renders as 0.977 MiB - 1058223158 with base 2 and precision 3 renders as 0.986 GiB - 392 with precision 1 and round 0 renders as 0.4 kB
Merged
6 of 15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds unit tests for precision rounding at unit boundaries and with the
roundoption, and fixes the bug they exposed: whenprecisionproduced scientific notation,applyPrecisionHandlingrounded the value torounddecimals and then appliedtoPrecision, rounding twice. It now appliestoPrecisionto the unrounded value (src/helpers.js). No public API or signature changes.dist/is rebuilt.Two existing tests expected
0.990 GiB/gibibytesforfilesize(1058223158, {precision: 3, ...}). That was an artifact of the double rounding; the true value is 0.98555 GiB, so they now expect0.986.Type of Change
Related Issues
Refs #399, #404, #414, #415 (precision rounding)
Testing
npm test(lint +node:testwith coverage): 283 tests, 283 pass, 0 fail. The 3 newprecision roundingtests previously failed and now pass. Coverage is 100% statements/branches/functions/lines forfilesize.jsandhelpers.js.npm run buildsucceeds.Checklist
npm testpassesnpm run buildsucceedsauto-changelog)Screenshots (if applicable)
N/A
Closes #413