public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer] get_device_desc: display disk size with 2 decimal places
@ 2022-01-25 13:04 Stoiko Ivanov
  2022-01-26 11:03 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2022-01-25 13:04 UTC (permalink / raw)
  To: pve-devel

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH installer] get_device_desc: display disk size with 2 decimal places
  2022-01-25 13:04 [pve-devel] [PATCH installer] get_device_desc: display disk size with 2 decimal places Stoiko Ivanov
@ 2022-01-26 11:03 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2022-01-26 11:03 UTC (permalink / raw)
  To: Proxmox VE development discussion, Stoiko Ivanov

On 25.01.22 14:04, Stoiko Ivanov wrote:
> 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

In general I really do not find that too pleasing, but here I think that first,
knowing the cheapness of HW vendors and TB vs TiB exact sizes won't happen often
and second, keeping it simple in the installer has quite some merit, so your
solutions works fine for me here.

> 
> 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(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-26 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 13:04 [pve-devel] [PATCH installer] get_device_desc: display disk size with 2 decimal places Stoiko Ivanov
2022-01-26 11:03 ` [pve-devel] applied: " Thomas Lamprecht

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