emacs-devel
[Top][All Lists]
Advanced

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

Re: master 2b97e83cc1 2/2: Fix off-by-one file size formatting in ls-lis


From: Eli Zaretskii
Subject: Re: master 2b97e83cc1 2/2: Fix off-by-one file size formatting in ls-lisp
Date: Sun, 13 Feb 2022 15:40:21 +0200

> Date: Sun, 13 Feb 2022 14:55:09 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: salutis@me.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org
> 
> > From: Lars Ingebrigtsen <larsi@gnus.org>
> > Cc: Rudolf Adamkovič <salutis@me.com>,
> >   monnier@iro.umontreal.ca,
> >   emacs-devel@gnu.org
> > Date: Sun, 13 Feb 2022 13:36:50 +0100
> > 
> > Like I said in an earlier post, my test file is 1029204 bytes.
> > 
> > (file-size-human-readable 1029204)
> > -> "1005.1k"
> 
> Ah, okay.  So you want to lose accuracy in these cases and just throw
> away the fractional part?  Why?
> 
> I'm quite sure "ls -lh" still does that, albeit perhaps not with this
> specific size.

For example, with these sizes:

  1124 => 1.1K
  4939 => 4.9K
  8255 => 8.1K
  1188708 => 1.2M
  6916144 => 6.6M

So how about the patch below:

diff --git a/lisp/files.el b/lisp/files.el
index cfa1a59..7e62726 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1494,7 +1494,8 @@ file-size-human-readable
                                (or unit "B"))
                             (concat prefix unit))))
       (format (if (and (>= (mod file-size 1.0) 0.05)
-                       (< (mod file-size 1.0) 0.95))
+                       (< (mod file-size 1.0) 0.95)
+                       (< file-size 10))
                  "%.1f%s%s"
                "%.0f%s%s")
              file-size



reply via email to

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