aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2022-02-14 18:59:38 +0200
committerEli Zaretskii2022-02-14 18:59:38 +0200
commita90dc11e24895c4e6e5bfcfc991d8524f4075223 (patch)
tree988438de0bc612dd10c07841ef7d1ac4494748a5
parent3a3387f58e64f5e119ead50456c2fa6cef1e195b (diff)
downloademacs-a90dc11e24895c4e6e5bfcfc991d8524f4075223.tar.gz
emacs-a90dc11e24895c4e6e5bfcfc991d8524f4075223.zip
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.
-rw-r--r--lisp/files.el7
1 files changed, 6 insertions, 1 deletions
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."
1493 (if (string= prefix "") "" "i") 1493 (if (string= prefix "") "" "i")
1494 (or unit "B")) 1494 (or unit "B"))
1495 (concat prefix unit)))) 1495 (concat prefix unit))))
1496 (format (if (and (>= (mod file-size 1.0) 0.05) 1496 ;; Mimic what GNU "ls -lh" does:
1497 ;; If the formatted size will have just one digit before the decimal...
1498 (format (if (and (< file-size 10)
1499 ;; ...and its fractional part is not too small...
1500 (>= (mod file-size 1.0) 0.05)
1497 (< (mod file-size 1.0) 0.95)) 1501 (< (mod file-size 1.0) 0.95))
1502 ;; ...then emit one digit after the decimal.
1498 "%.1f%s%s" 1503 "%.1f%s%s"
1499 "%.0f%s%s") 1504 "%.0f%s%s")
1500 file-size 1505 file-size