json viewer: updated size display

This commit is contained in:
dswbx
2025-08-28 19:35:32 +02:00
parent dcf88cf587
commit 8f471a29b0
2 changed files with 6 additions and 4 deletions

View File

@@ -14,10 +14,10 @@ export function ensureInt(value?: string | number | null | undefined): number {
export const formatNumber = {
fileSize: (bytes: number, decimals = 2): string => {
if (bytes === 0) return "0 Bytes";
if (bytes === 0) return "0 B";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
const sizes = ["B", "KB", "MB", "GB", "TB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Number.parseFloat((bytes / k ** i).toFixed(dm)) + " " + sizes[i];
},