Skip to content

Instantly share code, notes, and snippets.

@deep5050
Created September 30, 2019 13:34
Show Gist options
  • Save deep5050/fb09be5e39a970ca862f2206e3ffa283 to your computer and use it in GitHub Desktop.
Save deep5050/fb09be5e39a970ca862f2206e3ffa283 to your computer and use it in GitHub Desktop.
var bytesToSize = function (a, b) {
if (0 === a) return "0 Bytes";
var c = 1024, d = b || 2, e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
f = Math.floor(Math.log(a) / Math.log(c));
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment