格式化文件大小

formatFileSize: function (size, u) {
u = u ? u : 0;
var sizeUnit = ['B', 'KB', 'MB', 'GB', 'TB'];
if (u < 0 || u >= sizeUnit.length) {
return '0B';
};
if (size < 1) {
return this.formatFileSize(size * 1024, --u);
} else if (size < 1024) {
return Math.ceil(size * 1000) / 1000 + sizeUnit[u];
} else {
return this.formatFileSize(size / 1024, ++u);
}
},

原文地址:https://www.cnblogs.com/yanypan/p/2848645.html