Fix byte size conversion

This commit is contained in:
schlagmichdoch 2023-10-12 20:13:40 +02:00
parent e5a09b6be1
commit c670b39732

View file

@ -919,19 +919,21 @@ class ReceiveDialog extends Dialog {
} }
_formatFileSize(bytes) { _formatFileSize(bytes) {
// 1 GB = 1024 MB = 1024^2 KB = 1024^3 B // 1 GB = 1e3 MB = 1e6 KB = 1e9 B
// 1024^2 = 104876; 1024^3 = 1073741824 if (bytes >= 1e9) {
if (bytes >= 1073741824) { const rndGigabytes = Math.round(10 * bytes / 1e9) / 10;
return Math.round(10 * bytes / 1073741824) / 10 + ' GB'; return `${rndGigabytes} GB`;
} }
else if (bytes >= 1048576) { else if (bytes >= 1e6) {
return Math.round(bytes / 1048576) + ' MB'; const rndMegabytes = Math.round(10 * bytes / 1e6) / 10;
return `${rndMegabytes} MB`;
} }
else if (bytes > 1024) { else if (bytes >= (1e3)) {
return Math.round(bytes / 1024) + ' KB'; const rndKilobytes = Math.round(10 * bytes / 1e3) / 10;
return `${rndKilobytes} KB`;
} }
else { else {
return bytes + ' Bytes'; return `${bytes} bytes`;
} }
} }