mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 10:28:32 +00:00
(web) Math.roundWithPrecision does the exact same thing as toFixed.
This commit is contained in:
@@ -107,18 +107,6 @@ function setInnerHTML( e, html )
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Round a float to a specified number of decimal
|
||||
* places, stripping trailing zeroes
|
||||
*
|
||||
* @param float floatnum
|
||||
* @param integer precision
|
||||
* @returns float
|
||||
*/
|
||||
Math.roundWithPrecision = function(floatnum, precision) {
|
||||
return Math.round( floatnum * Math.pow ( 10, precision ) ) / Math.pow( 10, precision );
|
||||
};
|
||||
|
||||
/*
|
||||
* Given a numerator and denominator, return a ratio string
|
||||
*/
|
||||
|
||||
@@ -72,22 +72,22 @@ Transmission.fmt = (function()
|
||||
return 'None';
|
||||
|
||||
if( bytes < KB_val )
|
||||
return bytes.toFixed(0) + ' B';
|
||||
return bytes.toFixed(10) + ' B';
|
||||
|
||||
if( bytes < ( KB_val * 100 ) )
|
||||
return Math.roundWithPrecision(bytes/KB_val, 2) + ' ' + KB_str;
|
||||
return (bytes/KB_val).toFixed(2) + ' ' + KB_str;
|
||||
if( bytes < MB_val )
|
||||
return Math.roundWithPrecision(bytes/KB_val, 1) + ' ' + KB_str;
|
||||
return (bytes/KB_val).toFixed(1) + ' ' + KB_str;
|
||||
|
||||
if( bytes < ( MB_val * 100 ) )
|
||||
return Math.roundWithPrecision(bytes/MB_val, 2) + ' ' + MB_str;
|
||||
return (bytes/MB_val).toFixed(2) + ' ' + MB_str;
|
||||
if( bytes < GB_val )
|
||||
return Math.roundWithPrecision(bytes/MB_val, 1) + ' ' + MB_str;
|
||||
return (bytes/MB_val).toFixed(1) + ' ' + MB_str;
|
||||
|
||||
if( bytes < ( GB_val * 100 ) )
|
||||
return Math.roundWithPrecision(bytes/GB_val, 2) + ' ' + GB_str;
|
||||
return (bytes/GB_val).toFixed(2) + ' ' + GB_str;
|
||||
else
|
||||
return Math.roundWithPrecision(bytes/GB_val, 1) + ' ' + GB_str;
|
||||
return (bytes/GB_val).toFixed(1) + ' ' + GB_str;
|
||||
},
|
||||
|
||||
speed: function( bytes )
|
||||
|
||||
Reference in New Issue
Block a user