Skip to content

fix: use HumanSize for image list to avoid scientific notation#7059

Open
amarkdotdev wants to merge 1 commit into
docker:masterfrom
amarkdotdev:fix/image-size-scientific-notation
Open

fix: use HumanSize for image list to avoid scientific notation#7059
amarkdotdev wants to merge 1 commit into
docker:masterfrom
amarkdotdev:fix/image-size-scientific-notation

Conversation

@amarkdotdev

Copy link
Copy Markdown

Description

docker image ls reports image sizes near 1000 MB as 1e+03MB instead of a human-readable value like 999.5MB.

Root cause

The Size() method in cli/command/formatter/image.go calls units.HumanSizeWithPrecision(float64(c.i.Size), 3). The %g format 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 by SharedSize(), 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):

Bytes Output
999,500,000 1e+03MB
999,900,000 1e+03MB

After (precision=4 via HumanSize):

Bytes Output
999,500,000 999.5MB
999,900,000 999.9MB

Normal-range sizes remain unchanged (e.g. 796kB, 1.5GB).

Fixes #3091

  • I've verified the fix with a standalone reproduction of the formatting logic
  • The change is a single line: HumanSizeWithPrecision(..., 3)HumanSize(...)

@amarkdotdev amarkdotdev force-pushed the fix/image-size-scientific-notation branch from 37f7579 to c32a578 Compare June 18, 2026 15:00
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>
@amarkdotdev amarkdotdev force-pushed the fix/image-size-scientific-notation branch from c32a578 to b159dfb Compare June 21, 2026 06:37
@vvoland vvoland requested a review from docker-agent July 6, 2026 13:08
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@amarkdotdev

Copy link
Copy Markdown
Author

Thanks @docker-agent for the review.

validate-milestone is failing because no milestone is set on the PR (expected 29.7.0 per current VERSION). I don't have permission to set milestones on this repo — could a maintainer add it when convenient? All other checks are green.

@docker-agent

Copy link
Copy Markdown
Contributor

Sorry @amarkdotdev, I can only respond to Docker org members.

@amarkdotdev

Copy link
Copy Markdown
Author

@vvoland
😀 can you take a look please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image size reported as 1e+03MB by docker image ls

3 participants