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(...)

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>
@amarkdotdev amarkdotdev force-pushed the fix/image-size-scientific-notation branch from 37f7579 to c32a578 Compare June 18, 2026 15:00
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

1 participant