0
点赞
收藏
分享

微信扫一扫

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

楚木巽 2021-09-25 阅读 29
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 条评论