Nodejs Size Format formatSizeUnits(bytes)

Here you can find the source of formatSizeUnits(bytes)

Method Source Code

/* Utilities *///from   w  w  w .  ja  va 2s .c  o  m
function formatSizeUnits(bytes){
      if(bytes == 0) 
         return '0 Bytes';
      var k = 1000,dm = 2,sizes = ['B', 'kB', 'MB', 'GB', 'TB'],
          i = Math.floor(Math.log(bytes) / Math.log(k));
      return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
};
String.prototype.UCFirst = function() {return this.charAt(0).toUpperCase() + this.slice(1);};

Related

  1. formatSize(bytes)
    function formatSize(bytes) {
      if (bytes > 1024*1024*1024) {
        return Math.round(bytes/1024/1024/1024*100)/100+"GB";
      if (bytes > 1024*1024) {
        return Math.round(bytes/1024/1024*10)/10+"MB";
      if (bytes > 1024) {
        return Math.round(bytes/1024)+"KB";
    ...