From 58fe46f1de9a51461fc444e9b57333a8f6ac3527 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 16 Aug 2021 14:57:38 +0200 Subject: [PATCH] improved sizeToReadable --- src/functions/sizeToReadable.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions/sizeToReadable.ts b/src/functions/sizeToReadable.ts index 0a3df26..ecd4ec3 100644 --- a/src/functions/sizeToReadable.ts +++ b/src/functions/sizeToReadable.ts @@ -1,6 +1,7 @@ function sizeToReadable(size: number): string { const i = Math.floor(Math.log(size) / Math.log(1024)) - return (size / Math.pow(1024, i)).toFixed(1) + " " + ["B", "kB", "MB", "GB", "TB"][i] + const num = (size / Math.pow(1024, i)) + return (num.toFixed(1).endsWith("0")?num.toFixed(0):num.toFixed(1)) + " " + ["B", "kB", "MB", "GB", "TB"][i] }