Changeset 10807


Ignore:
Timestamp:
Jun 19, 2010, 9:42:16 PM (13 years ago)
Author:
Longinus00
Message:

refactor formatter.js

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/formatter.js

    r10806 r10807  
    1414        var MB_str = 'MiB';
    1515        var GB_str = 'GiB';
    16 
    17         /**
    18          * Round a number to a specified number of decimal places, stripping trailing zeroes
    19          * @param number floatnum
    20          * @param number precision
    21          * @returns number
    22          */
    23         var roundWithPrecision = function(floatnum, precision) {
    24                 return Math.round ( floatnum * Math.pow ( 10, precision ) ) / Math.pow ( 10, precision );
    25         };
    2616
    2717        return {
     
    4737                },
    4838
    49 
    5039                /**
    5140                 * Formats the bytes into a string value with B, KiB, MiB, or GiB units.
     
    6352
    6453                        if( bytes < ( KB_val * 100 ) )
    65                                 return roundWithPrecision(bytes/KB_val, 2) + ' ' + KB_str;
     54                                return Math.roundWithPrecision(bytes/KB_val, 2) + ' ' + KB_str;
    6655                        if( bytes < MB_val )
    67                                 return roundWithPrecision(bytes/KB_val, 1) + ' ' + KB_str;
     56                                return Math.roundWithPrecision(bytes/KB_val, 1) + ' ' + KB_str;
    6857
    6958                        if( bytes < ( MB_val * 100 ) )
    70                                 return roundWithPrecision(bytes/MB_val, 2) + ' ' + MB_str;
     59                                return Math.roundWithPrecision(bytes/MB_val, 2) + ' ' + MB_str;
    7160                        if( bytes < GB_val )
    72                                 return roundWithPrecision(bytes/MB_val, 1) + ' ' + MB_str;
    73 
     61                                return Math.roundWithPrecision(bytes/MB_val, 1) + ' ' + MB_str;
    7462
    7563                        if( bytes < ( GB_val * 100 ) )
    76                                 return roundWithPrecision(bytes/GB_val, 2) + ' ' + GB_str;
     64                                return Math.roundWithPrecision(bytes/GB_val, 2) + ' ' + GB_str;
    7765                        else
    78                                 return roundWithPrecision(bytes/GB_val, 1) + ' ' + GB_str;
     66                                return Math.roundWithPrecision(bytes/GB_val, 1) + ' ' + GB_str;
    7967                },
    8068
Note: See TracChangeset for help on using the changeset viewer.