diff --git a/ts/components/Lightbox.tsx b/ts/components/Lightbox.tsx index 6c1fbe045f5..7d1767b7981 100644 --- a/ts/components/Lightbox.tsx +++ b/ts/components/Lightbox.tsx @@ -775,10 +775,9 @@ export function Lightbox({ {attachment.totalDownloaded && attachment.size ? i18n('icu:lightBoxDownloading', { downloaded: formatFileSize( - attachment.totalDownloaded, - 2 + attachment.totalDownloaded ), - total: formatFileSize(attachment.size, 2), + total: formatFileSize(attachment.size), }) : undefined} diff --git a/ts/components/conversation/AttachmentDetailPill.tsx b/ts/components/conversation/AttachmentDetailPill.tsx index 11ad507b5ad..044b92a8853 100644 --- a/ts/components/conversation/AttachmentDetailPill.tsx +++ b/ts/components/conversation/AttachmentDetailPill.tsx @@ -126,7 +126,7 @@ export function AttachmentDetailPill({ ); text = (
- {formatFileSize(totalSize, 2)} + {formatFileSize(totalSize)}
); } else if (totalDownloadedSize > 0) { @@ -148,9 +148,9 @@ export function AttachmentDetailPill({ text = (
{totalDownloadedSize > 0 && areAnyPending - ? `${formatFileSize(totalDownloadedSize, 2)} / ` + ? `${formatFileSize(totalDownloadedSize)} / ` : undefined} - {formatFileSize(totalSize, 2)} + {formatFileSize(totalSize)}
); } else { @@ -165,7 +165,7 @@ export function AttachmentDetailPill({ ); text = (
- {formatFileSize(totalSize, 2)} + {formatFileSize(totalSize)}
); } @@ -191,9 +191,9 @@ export function AttachmentDetailPill({
{totalDownloadedSize > 0 && areAnyPending - ? `${formatFileSize(totalDownloadedSize, 2)} / ` + ? `${formatFileSize(totalDownloadedSize)} / ` : undefined} - {formatFileSize(totalSize, 2)} + {formatFileSize(totalSize)} {isGif ? ' ยท GIF' : undefined}
diff --git a/ts/util/formatFileSize.ts b/ts/util/formatFileSize.ts index bc2f2f622b2..d4101e163dd 100644 --- a/ts/util/formatFileSize.ts +++ b/ts/util/formatFileSize.ts @@ -2,6 +2,9 @@ // SPDX-License-Identifier: AGPL-3.0-only import filesize from 'filesize'; -export function formatFileSize(size: number, decimals = 0): string { - return filesize(size, { round: decimals }); +// Intentional, `filesize` uses `jedec` standard by default +const MB = 1000 * 1000; + +export function formatFileSize(size: number): string { + return filesize(size, { round: size < MB ? 0 : 1 }); }