]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve format of values returned by 'file-size-human-readable'
authorEli Zaretskii <eliz@gnu.org>
Mon, 14 Feb 2022 16:59:38 +0000 (18:59 +0200)
committerEli Zaretskii <eliz@gnu.org>
Mon, 14 Feb 2022 16:59:38 +0000 (18:59 +0200)
* 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

index cfa1a5972c8e48a0d87f69e1e0a1f0a4a5dfb6f0..b2792818e67b88f56fd91b459090386398818385 100644 (file)
@@ -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