Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active August 29, 2015 14:14
Show Gist options
  • Save appkr/e102e0855270da071b1a to your computer and use it in GitHub Desktop.
Save appkr/e102e0855270da071b1a to your computer and use it in GitHub Desktop.
JavaScript numberFormat(), formatFileSize
var Utility = {
getBitRate = function(size, duration) {
return numberFormat(Math.round((size * 8) / duration));
},
numberFormat = function(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
},
formatFileSize = function(size) {
if (isNaN(size)) return 'NaN';
decr = 1024;
step = 0;
suffix = ['b', 'KiB', 'MiB', 'GiB'];
while ((size / decr) > 0.9) {
size = size / decr;
step ++;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment