daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Jun 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Formats a file size as b, Kb, Mb etc
  3. * @param (number) size File size in bytes
  4. * @param (number) dec Number of decimal points to round to
  5. */
  6. function formatFileSize(size, dec)
  7. {
  8.     if(isNaN(dec)) dec = 2;
  9.     var multiply = Math.pow(10, dec);
  10.     var units = ['b','Kb','Mb','Gb','Tb','Pb'];
  11.     var exponent = Math.floor(Math.log(size)/Math.log(1024));
  12.     return (Math.round(size/Math.pow(1024, exponent) * multiply) / multiply) + units[exponent];
  13. }
RAW Paste Data
Top