From 0eb2b4fe6bd925d15f5d9a4b6e1056cadd26d0f7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 1 Mar 2021 15:02:02 +0100 Subject: [PATCH] simplify with toFixed here --- src/utils/formatSize.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/formatSize.js b/src/utils/formatSize.js index c8a6ea1e..d001dacd 100644 --- a/src/utils/formatSize.js +++ b/src/utils/formatSize.js @@ -17,8 +17,7 @@ limitations under the License. export function formatSize(size, decimals = 2) { if (Number.isSafeInteger(size)) { const base = Math.min(3, Math.floor(Math.log(size) / Math.log(1024))); - const decimalFactor = Math.pow(10, decimals); - const formattedSize = Math.round((size / Math.pow(1024, base)) * decimalFactor) / decimalFactor; + const formattedSize = Math.round(size / Math.pow(1024, base)).toFixed(decimals); switch (base) { case 0: return `${formattedSize} bytes`; case 1: return `${formattedSize} KB`;