public static String getNetFileSizeDescription(long size) {
        StringBuffer bytes = new StringBuffer();
        DecimalFormat format = new DecimalFormat("#####.0");
        if (size >= 1024 * 1024 * 1024) {
            double i = (size / (1024.0 * 1024.0 * 1024.0));
            bytes.append(format.format(i)).append("GB");
        }
        else if (size >= 1024 * 1024) {
            double i = (size / (1024.0 * 1024.0));
            bytes.append(format.format(i)).append("MB");
        }
        else if (size >= 1024) {
            double i = (size / (1024.0));
            bytes.append(format.format(i)).append("KB");
        }
        else if (size < 1024) {
            if (size <= 0) {
                bytes.append("0B");
            }
            else {
                bytes.append((int) size).append("B");
            }
        }

        return bytes.toString();
    }

非本人原创

相关文章:

  • 2021-07-25
  • 2021-09-05
  • 2021-07-01
  • 2022-12-23
  • 2022-02-11
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2021-05-19
  • 2022-01-21
  • 2021-05-27
  • 2021-11-15
  • 2022-12-23
  • 2021-12-10
  • 2021-07-02
相关资源
相似解决方案