原文出自:https://blog.csdn.net/seesun2012
.net
// 格式化文件大小 function renderSize(value){ if(null==value||value==''){ return "0 Bytes"; } var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"); var index=0, srcsize = parseFloat(value); index=Math.floor(Math.log(srcsize)/Math.log(1024)); var size =srcsize/Math.pow(1024,index); // 保留的小數位數 size=size.toFixed(2); return size+unitArr[index]; }