fix: prevent 1000 unit prefix output by rolling over on boundary rounding - #169
Closed
AdamMagued wants to merge 1 commit into
Closed
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
…ding When byte values close to a unit boundary (such as 999,950 bytes or MByte - Byte) are formatted, rounding at the display precision can cause the formatted value to reach the unit threshold (e.g. 1000 kB or 1024 KiB) instead of rolling over into the next unit (e.g. 1.0 MB or 1.0 MiB). This change checks whether the rounded value reaches or exceeds the base threshold before emitting the formatted string. If so, and if higher unit sizes are available, the magnitude exponent is incremented, the value is scaled by the base, and formatting digits are recalculated. Fixes dustin#127
Author
|
Closing in favor of earlier community PR #160 to avoid duplicate review effort. |
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
When formatting byte values near unit boundaries (such as 999_950 bytes, MByte - Byte, or MiByte - IByte), rounding to the required display precision can produce values equal to the base magnitude (e.g. 1000 kB or 1024 KiB) instead of rolling over to the next unit (1.0 MB or 1.0 MiB).
Root Cause
In humanateBytes:
Solution
Fixes #127