From: Johannes Berg Date: Sun, 17 May 2020 21:45:21 +0000 (+0200) Subject: helpers: use float for format_filesize() X-Git-Tag: 0.31~76 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=3912ff3aa3ef75f79ccc6ec014c4a691d0e3803b helpers: use float for format_filesize() 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 Reviewed-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index d988685..5b0c458 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -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):