From bbc2da05f0b5ea948707a84a766a30adea6ca0ce Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Sat, 14 Dec 2024 21:49:48 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20FormatBytes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ui/src/utils/formatting.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/utils/formatting.ts b/packages/ui/src/utils/formatting.ts index ce43c22..7454401 100644 --- a/packages/ui/src/utils/formatting.ts +++ b/packages/ui/src/utils/formatting.ts @@ -2,11 +2,12 @@ import { intlFormat } from '@shadcn/ui/lib/date-fns'; export function formatBytes(bytes: number) { if (bytes === 0) return '0 B'; - const k = 1024, // or 1000 - sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], - i = Math.floor(Math.log(bytes) / Math.log(k)); - return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]; + const k = 1024; + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]; } export function formatDate(date?: Date | number, showTime: boolean = true) {