From a90dc11e24895c4e6e5bfcfc991d8524f4075223 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 14 Feb 2022 18:59:38 +0200 Subject: [PATCH] Improve format of values returned by 'file-size-human-readable' * lisp/files.el (file-size-human-readable): Emit one digit of the fractional part of the size only if there's just one digit before the decimal point. --- lisp/files.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index cfa1a5972c8..b2792818e67 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1493,8 +1493,13 @@ in all cases, since that is the standard symbol for byte." (if (string= prefix "") "" "i") (or unit "B")) (concat prefix unit)))) - (format (if (and (>= (mod file-size 1.0) 0.05) + ;; Mimic what GNU "ls -lh" does: + ;; If the formatted size will have just one digit before the decimal... + (format (if (and (< file-size 10) + ;; ...and its fractional part is not too small... + (>= (mod file-size 1.0) 0.05) (< (mod file-size 1.0) 0.95)) + ;; ...then emit one digit after the decimal. "%.1f%s%s" "%.0f%s%s") file-size -- 2.39.5