From 3514c43014fce57ccb2e49a71b85c552edcd05c0 Mon Sep 17 00:00:00 2001 From: p0358 Date: Thu, 7 Jul 2022 18:53:55 +0200 Subject: [PATCH] improve the display of sizes --- renderer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/renderer.js b/renderer.js index afcabbf..dfc483a 100644 --- a/renderer.js +++ b/renderer.js @@ -225,10 +225,10 @@ function showFileDetails(f) { function bytesToSize(bytes) { - var sizes = [' bytes', 'KB', 'MB', 'GB', 'TB']; - if (bytes == 0) return '0 bytes'; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return (bytes / Math.pow(1024, i)).toFixed(2) + sizes[i]; + let sizes = ['bytes', 'KB', 'MB', 'GB', 'TB']; + if (bytes === 0) return '0 bytes'; + let i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return (bytes / Math.pow(1024, i)).toFixed(i > 0 ? 2 : 0) + ' ' + sizes[i]; } async function unpackDir(d) {