fix: use HumanSize for image list to avoid scientific notation#7059
Open
amarkdotdev wants to merge 1 commit into
Open
fix: use HumanSize for image list to avoid scientific notation#7059amarkdotdev wants to merge 1 commit into
amarkdotdev wants to merge 1 commit into
Conversation
The Size() method in the image formatter used HumanSizeWithPrecision with precision=3, which causes fmt %g to emit scientific notation (1e+03MB) when a size rounds to exactly 1000 in its current unit (e.g. an image of ~999.5 MB). Switch to HumanSize() which uses precision=4 (the standard across the rest of the CLI) and avoids this edge case while still producing compact human-readable output. Fixes docker#3091 Signed-off-by: Aaron <aaroniofjm@gmail.com>
37f7579 to
c32a578
Compare
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.
Description
docker image lsreports image sizes near 1000 MB as1e+03MBinstead of a human-readable value like999.5MB.Root cause
The
Size()method incli/command/formatter/image.gocallsunits.HumanSizeWithPrecision(float64(c.i.Size), 3). The%gformat verb with precision=3 uses 3 significant digits, so when a value like 999.5 rounds to 1000 (which requires 4 significant digits), Go's formatter falls back to scientific notation:1e+03.Fix
Switch to
units.HumanSize()which uses precision=4 (the standard used bySharedSize(),UniqueSize(), and most other callers in this codebase). This avoids the scientific notation edge case while still producing compact, human-readable output.Before (precision=3):
1e+03MB1e+03MBAfter (precision=4 via HumanSize):
999.5MB999.9MBNormal-range sizes remain unchanged (e.g.
796kB,1.5GB).Fixes #3091
HumanSizeWithPrecision(..., 3)→HumanSize(...)