]> arthur.barton.de Git - bup.git/commitdiff
helpers: use float for format_filesize()
authorJohannes Berg <johannes@sipsolutions.net>
Sun, 17 May 2020 21:45:21 +0000 (23:45 +0200)
committerRob Browning <rlb@defaultvalue.org>
Wed, 20 May 2020 06:02:40 +0000 (01:02 -0500)
In format_filesize(), we really do want float division,
in order to display the value correctly. For example, if
there's a file with 45200000 bytes, that should be shown
as 43.1 MB, not 43.0. Fix this by using proper float
division here, not int division.

Fixes: a5809723352c ("helpers: use // not / for division")
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index d9886854c091f0f5ff473c386c3446325813063f..5b0c458f0a8a3abcaf748856a5f89660a90eb971 100644 (file)
@@ -445,7 +445,7 @@ def format_filesize(size):
         return "%d" % (size)
     exponent = int(math.log(size) // math.log(unit))
     size_prefix = "KMGTPE"[exponent - 1]
-    return "%.1f%s" % (size // math.pow(unit, exponent), size_prefix)
+    return "%.1f%s" % (size / math.pow(unit, exponent), size_prefix)
 
 
 class NotOk(Exception):