Skip to content

formatBytes

Formats a byte count into a human-readable size string.

ts
import { formatBytes } from '@swapped/connect-sdk/format'

formatBytes(0)
// "0.0B"

formatBytes(500)
// "500.0B"

formatBytes(1024)
// "1.0KB"

formatBytes(1536)
// "1.5KB"

formatBytes(1_048_576)
// "1.0MB"

formatBytes(1_572_864)
// "1.6MB"