From 633f56d8ab54b9d96e7b37d64048b4d2392fb372 Mon Sep 17 00:00:00 2001 From: Ayu-haker Date: Sat, 20 Jun 2026 09:06:55 +0000 Subject: [PATCH] vendor: github.com/docker/go-units: avoid scientific notation in HumanSizeWithPrecision When HumanSizeWithPrecision formats a value that rounds to the next unit boundary (e.g., 999.5MB rounds to 1000 with 3 significant digits), Go's %g format switches to scientific notation (1e+03MB) because the exponent (3) >= precision (3). Detect scientific notation in the output and reformat using %.0f to produce human-readable output like '1000MB'. Upstream: https://github.com/docker/go-units/pull/53 Fixes docker/cli#3091 --- vendor/github.com/docker/go-units/size.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vendor/github.com/docker/go-units/size.go b/vendor/github.com/docker/go-units/size.go index c245a89513f8..311f01cf0b11 100644 --- a/vendor/github.com/docker/go-units/size.go +++ b/vendor/github.com/docker/go-units/size.go @@ -58,7 +58,13 @@ func CustomSize(format string, size float64, base float64, _map []string) string // instead of 4 digit precision used in units.HumanSize. func HumanSizeWithPrecision(size float64, precision int) string { size, unit := getSizeAndUnit(size, 1000.0, decimapAbbrs) - return fmt.Sprintf("%.*g%s", precision, size, unit) + // Use %g format, but avoid scientific notation edge case + // (e.g., 999.5MB displaying as "1e+03MB" instead of "1000MB") + result := fmt.Sprintf("%.*g%s", precision, size, unit) + if strings.ContainsAny(result, "eE") { + result = fmt.Sprintf("%.0f%s", size, unit) + } + return result } // HumanSize returns a human-readable approximation of a size