###對數log 的妙用。。。spa
formatBytes(bytes) {orm
if (bytes === '0' || isNaN(bytes)) return '';io
var s = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];function
var e = Math.floor(Math.log(bytes) / Math.log(1024));form
return (bytes / Math.pow(1024, Math.floor(e))).toFixed(1) + " " + s[e];class
},總結
function formatBytes(nums) {
if (nums === '0' || isNaN(nums)) return '';
var s = ['s', 'm', 'H'];
var e = Math.floor(Math.log(nums) / Math.log(60));
return (nums / Math.pow(60, Math.floor(e))).toFixed(1) + ' ' + s[e];
}co
總結: 存在規律的進制轉換的狀況,好比 mb和byte都是1024 ;好比s秒和m分 都是60 。return