Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Last active February 16, 2026 02:22
Show Gist options
  • Select an option

  • Save thomseddon/3511330 to your computer and use it in GitHub Desktop.

Select an option

Save thomseddon/3511330 to your computer and use it in GitHub Desktop.

Revisions

  1. thomseddon revised this gist Apr 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ app.filter('bytes', function() {
    if (typeof precision === 'undefined') precision = 1;
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    }
    });
  2. thomseddon created this gist Aug 29, 2012.
    9 changes: 9 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    app.filter('bytes', function() {
    return function(bytes, precision) {
    if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    }
    });