Skip to content

Instantly share code, notes, and snippets.

@sja
Created August 2, 2012 09:12
Show Gist options
  • Save sja/3235704 to your computer and use it in GitHub Desktop.
Save sja/3235704 to your computer and use it in GitHub Desktop.
ExtJS 4 overridden Ext.util.Format.fileSize for bigger sizes like GB and TB
/**
* Overridden Ext.util.Format.fileSize for bigger sizes like GB and TB and support localized formats
*
* Simple format for a file size (xxx bytes, xxx KB, xxx MB, xxx GB, xxx TB)
*
* @param {Number/String}
* size The numeric value to format
* @return {String} The formatted file size
*/
Ext.util.Format.fileSize = function(size, formatString) {
var numberFormatString = formatString || '0.,00/i';
if (size < 1024) {
return Ext.util.Format.number(size, numberFormatString) + " B";
} else if (size < 1048576) {
return Ext.util.Format.number(Math.round(((size * 100) / 1024)) / 100, numberFormatString) + " KB";
} else if (size < 1073741824) {
return Ext.util.Format.number(Math.round(((size * 100) / 1048576)) / 100, numberFormatString) + " MB";
} else if (size < 1099511627776) {
return Ext.util.Format.number(Math.round(((size * 100) / 1073741824)) / 100, numberFormatString) + " GB";
} else {
return Ext.util.Format.number(Math.round(((size * 100) / 1099511627776)) / 100, numberFormatString) + " TB";
}
};
@vhieragang
Copy link

how can I put this code into my secha architect 4.2? thanks in advance!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment