Changeset 10807
- Timestamp:
- Jun 19, 2010, 9:42:16 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/javascript/formatter.js
r10806 r10807 14 14 var MB_str = 'MiB'; 15 15 var GB_str = 'GiB'; 16 17 /**18 * Round a number to a specified number of decimal places, stripping trailing zeroes19 * @param number floatnum20 * @param number precision21 * @returns number22 */23 var roundWithPrecision = function(floatnum, precision) {24 return Math.round ( floatnum * Math.pow ( 10, precision ) ) / Math.pow ( 10, precision );25 };26 16 27 17 return { … … 47 37 }, 48 38 49 50 39 /** 51 40 * Formats the bytes into a string value with B, KiB, MiB, or GiB units. … … 63 52 64 53 if( bytes < ( KB_val * 100 ) ) 65 return roundWithPrecision(bytes/KB_val, 2) + ' ' + KB_str;54 return Math.roundWithPrecision(bytes/KB_val, 2) + ' ' + KB_str; 66 55 if( bytes < MB_val ) 67 return roundWithPrecision(bytes/KB_val, 1) + ' ' + KB_str;56 return Math.roundWithPrecision(bytes/KB_val, 1) + ' ' + KB_str; 68 57 69 58 if( bytes < ( MB_val * 100 ) ) 70 return roundWithPrecision(bytes/MB_val, 2) + ' ' + MB_str;59 return Math.roundWithPrecision(bytes/MB_val, 2) + ' ' + MB_str; 71 60 if( bytes < GB_val ) 72 return roundWithPrecision(bytes/MB_val, 1) + ' ' + MB_str; 73 61 return Math.roundWithPrecision(bytes/MB_val, 1) + ' ' + MB_str; 74 62 75 63 if( bytes < ( GB_val * 100 ) ) 76 return roundWithPrecision(bytes/GB_val, 2) + ' ' + GB_str;64 return Math.roundWithPrecision(bytes/GB_val, 2) + ' ' + GB_str; 77 65 else 78 return roundWithPrecision(bytes/GB_val, 1) + ' ' + GB_str;66 return Math.roundWithPrecision(bytes/GB_val, 1) + ' ' + GB_str; 79 67 }, 80 68
Note: See TracChangeset
for help on using the changeset viewer.