From c670b39732b6a2ecc509be8eaebc570210d2148d Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Thu, 12 Oct 2023 20:13:40 +0200 Subject: [PATCH] Fix byte size conversion --- public/scripts/ui.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 27cae3f..9bc51c2 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -919,19 +919,21 @@ class ReceiveDialog extends Dialog { } _formatFileSize(bytes) { - // 1 GB = 1024 MB = 1024^2 KB = 1024^3 B - // 1024^2 = 104876; 1024^3 = 1073741824 - if (bytes >= 1073741824) { - return Math.round(10 * bytes / 1073741824) / 10 + ' GB'; + // 1 GB = 1e3 MB = 1e6 KB = 1e9 B + if (bytes >= 1e9) { + const rndGigabytes = Math.round(10 * bytes / 1e9) / 10; + return `${rndGigabytes} GB`; } - else if (bytes >= 1048576) { - return Math.round(bytes / 1048576) + ' MB'; + else if (bytes >= 1e6) { + const rndMegabytes = Math.round(10 * bytes / 1e6) / 10; + return `${rndMegabytes} MB`; } - else if (bytes > 1024) { - return Math.round(bytes / 1024) + ' KB'; + else if (bytes >= (1e3)) { + const rndKilobytes = Math.round(10 * bytes / 1e3) / 10; + return `${rndKilobytes} KB`; } else { - return bytes + ' Bytes'; + return `${bytes} bytes`; } }