emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 9ab3f16: Fix formatting of (file-size-human-readabl


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 9ab3f16: Fix formatting of (file-size-human-readable 2047)
Date: Wed, 9 Oct 2019 19:58:04 -0400 (EDT)

branch: master
commit 9ab3f16c460d91aa556eb35085a90f168b10390f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Fix formatting of (file-size-human-readable 2047)
    
    * lisp/files.el (file-size-human-readable): Don't format
    slightly-less numbers as X.0k, but just Xk instead (bug#36329).
---
 lisp/files.el            | 3 ++-
 test/lisp/files-tests.el | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/files.el b/lisp/files.el
index fdd7c75..a1c7e3c 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1419,7 +1419,8 @@ in all cases, since that is the standard symbol for byte."
                                (if (string= prefix "") "" "i")
                                (or unit "B"))
                             (concat prefix unit))))
-      (format (if (> (mod file-size 1.0) 0.05)
+      (format (if (and (>= (mod file-size 1.0) 0.05)
+                       (< (mod file-size 1.0) 0.95))
                  "%.1f%s%s"
                "%.0f%s%s")
              file-size
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index ed23f76..60387e1 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1282,6 +1282,12 @@ renaming only, rather than modified in-place."
   (should (equal (file-size-human-readable 10000 'si " " "bit") "10 kbit"))
   (should (equal (file-size-human-readable 10000 'iec " " "bit") "9.8 Kibit"))
 
+  (should (equal (file-size-human-readable 2048) "2k"))
+  (should (equal (file-size-human-readable 2046) "2k"))
+  (should (equal (file-size-human-readable 2050) "2k"))
+  (should (equal (file-size-human-readable 1950) "1.9k"))
+  (should (equal (file-size-human-readable 2100) "2.1k"))
+
   (should (equal (file-size-human-readable-iec 0) "0 B"))
   (should (equal (file-size-human-readable-iec 1) "1 B"))
   (should (equal (file-size-human-readable-iec 9621) "9.4 KiB"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]