格式化上传附件大小的方法

楚木巽

关注

阅读 29

2021-09-25

formetFileSize: function (fileSize) {
    fileSize = parseFloat(fileSize);
    if (fileSize < 1024) {
      return Math.round(fileSize * 100) / 100.0 + 'B';
    } else if (fileSize < 1048576) {
      return Math.round((fileSize / 1024) * 100) / 100.0 + 'KB';
    } else if (fileSize < 1073741824) {
      return Math.round((fileSize / 1048576) * 100) / 100.0 + 'MB';
    } else {
      return Math.round((fileSize / 1073741824) * 100) / 100.0 + 'GB';
    }
  }

精彩评论(0)

0 0 举报