From 8054794a700863c7628d33719faf3393c884fad1 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 | 14 +++++++------- public_included_ws_fallback/scripts/ui.js | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 0dc5961..6bc48dc 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -748,14 +748,14 @@ 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'; - } else if (bytes >= 1048576) { - return Math.round(bytes / 1048576) + ' MB'; - } else if (bytes > 1024) { - return Math.round(bytes / 1024) + ' KB'; + if (bytes >= 1000000000) { + return Math.round(10 * bytes / 1000000000) / 10 + ' GB'; + } else if (bytes >= 1000000) { + return Math.round(10 * bytes / 1000000) / 10 + ' MB'; + } else if (bytes >= (1000)) { + return Math.round(10 * bytes / 1000) / 10 + ' KB'; } else { - return bytes + ' Bytes'; + return bytes + ' bytes'; } } diff --git a/public_included_ws_fallback/scripts/ui.js b/public_included_ws_fallback/scripts/ui.js index 11ee54c..834c246 100644 --- a/public_included_ws_fallback/scripts/ui.js +++ b/public_included_ws_fallback/scripts/ui.js @@ -750,14 +750,14 @@ 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'; - } else if (bytes >= 1048576) { - return Math.round(bytes / 1048576) + ' MB'; - } else if (bytes > 1024) { - return Math.round(bytes / 1024) + ' KB'; + if (bytes >= 1000000000) { + return Math.round(10 * bytes / 1000000000) / 10 + ' GB'; + } else if (bytes >= 1000000) { + return Math.round(10 * bytes / 1000000) / 10 + ' MB'; + } else if (bytes >= (1000)) { + return Math.round(10 * bytes / 1000) / 10 + ' KB'; } else { - return bytes + ' Bytes'; + return bytes + ' bytes'; } }