public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] get_device_desc: display disk size with 2 decimal places
Date: Tue, 25 Jan 2022 14:04:43 +0100	[thread overview]
Message-ID: <20220125130443.1163977-1-s.ivanov@proxmox.com> (raw)

instead of cutting it off by using int

especially relevant currently with 2 TB disks (people wonder why
it's displayed as 1 TiB - and would be fine with 1.95TiB).

Reported in our community forum:
https://forum.proxmox.com/threads/.103636/

Tested in a VM with a 100 GiB, 20GiB and 2TiB disk

Addtionally added the explicit return ath the end of the if branch,
instead of relying on the last statement not moving.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
Alternatively we could also use sprintf without decimal places for rounding
(Math::Round is a debian package of it's own) - if people consider
20.00GiB to not look too pleasing

Thanks to Dominik for insisting to see the code on this and suggesting
to actually improve it :)

 proxinstall | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/proxinstall b/proxinstall
index ae0e235..a39d405 100755
--- a/proxinstall
+++ b/proxinstall
@@ -2554,16 +2554,16 @@ sub get_device_desc {
     my ($devname, $size, $model) = @_;
 
     if ($size && ($size > 0)) {
-	$size = int($size/2048); # size in MB, from 512B "sectors"
+	$size = int($size/2048); # size in MiB, from 512B "sectors"
 
 	my $text = "$devname (";
 	if ($size >= 1024) {
-	    $size = int($size/1024); # size in GB
+	    $size = $size/1024; # size in GiB
 	    if ($size >= 1024) {
-		$size = int($size/1024); # size in GB
-		$text .= "${size}TiB";
+		$size = $size/1024; # size in TiB
+		$text .= sprintf("%.2f", $size) . "TiB";
 	    } else {
-		$text .= "${size}GiB";
+		$text .= sprintf("%.2f", $size) . "GiB";
 	    }
 	} else {
 	    $text .= "${size}MiB";
@@ -2571,6 +2571,7 @@ sub get_device_desc {
 
 	$text .= ", $model" if $model;
 	$text .= ")";
+	return $text;
 
     } else {
 	return $devname;
-- 
2.30.2





             reply	other threads:[~2022-01-25 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 13:04 Stoiko Ivanov [this message]
2022-01-26 11:03 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125130443.1163977-1-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal