From fe17d3517482525527d4af9b24df64e7651ebe3a Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 19 Nov 2012 10:35:04 -0800 Subject: Simplify human-readable size output * Limit human-readable sizes to a single decimal * Drop trailing zero * Step one suffix further in the case of a size being 1024 Change-Id: I2eb8ac0571d3d08b52f62155912863870573a37c --- glanceclient/common/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'glanceclient/common/utils.py') diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 628225d..ac4eef8 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -175,8 +175,11 @@ def make_size_human_readable(size): base = 1024.0 index = 0 - while size > base: + while size >= base: index = index + 1 size = size / base - return "%.3f%s" % (size, suffix[index]) + padded = '%.1f' % size + stripped = padded.rstrip('0').rstrip('.') + + return '%s%s' % (stripped, suffix[index]) -- cgit v1.2.1