From 0871de7e4fc0a4174f914b433612625ced844975 Mon Sep 17 00:00:00 2001 From: Christer Fletcher Date: Mon, 20 Oct 2025 15:32:20 +0200 Subject: [PATCH] Improve size_to_string Use a float instead to format the size to a string. And if the value is less than 10, show one decimal. --- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 48e5a50b..f151ee99 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -88,19 +88,20 @@ BLACKLIST_PKG_NAME = 0 -GIGABYTE = 1000 ** 3 -MEGABYTE = 1000 ** 2 -KILOBYTE = 1000 - def size_to_string(size): - if (size >= GIGABYTE): - return "%d %s" % (size // GIGABYTE, _("GB")) - if (size >= (MEGABYTE)): - return "%d %s" % (size // MEGABYTE, _("MB")) - if (size >= KILOBYTE): - return "%d %s" % (size // KILOBYTE, _("KB")) - return "%d %s" % (size, _("B")) + f_size = float(size) + units = [_('B'), _('KB'), _('MB'), _('GB')] + for unit in units: + if f_size >= 1000: + f_size /= 1000 + else: + break + if f_size >= 10: + return f"{f_size:.0f} {unit}" + else: + return f"{f_size:.1f} {unit}" + def name_search_func(model, column, key, iter): name = model.get_value(iter, column)