const sizeUnit = ['Bytes', 'KB', 'MB', 'GB', 'TB']; function formatSize(fileSizeInBytes) { const sizeType = parseInt( Math.floor(Math.log(fileSizeInBytes) / Math.log(1024)).toString(), ); console.log('sizeType', sizeType); const size = (fileSizeInBytes / Math.pow(1024, sizeType)).toFixed(2); return size + sizeUnit[sizeType]; }
标签:文件大小,const,log,fileSizeInBytes,js,格式化,sizeType,Math From: https://www.cnblogs.com/94pm/p/16756607.html