const units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; function niceBytes(x) { let l = 0, n = parseInt(x, 10) || 0; while (n >= 1000 && ++l) { n = n / 1000; } return n.toFixed(n < 10 && l > 0 ? 1 : 0) + " " + units[l]; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter