fix: use HumanSize for image list to avoid scientific notation - #7059
amarkdotdev wants to merge 1 commit into
Conversation
37f7579 to
c32a578
Compare
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 Mark <64331623+amarkdotdev@users.noreply.github.com>
c32a578 to
b159dfb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
|
Thanks @docker-agent for the review.
|
|
Sorry @amarkdotdev, I can only respond to Docker org members. |
|
@vvoland |
|
CI |
|
can't set the milestone from a fork - could someone add 29.8.0? |
|
validate-milestone still failing: I don't have permission to set milestones on this repo. Current |
|
still no milestone on this one from my side. validate-milestone expects the open 29.8.1 milestone per master VERSION. could a maintainer assign it? |
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(...)