美文网首页
字节转 B KB MB GB TB

字节转 B KB MB GB TB

作者: 指下光年 | 来源:发表于2022-08-05 14:06 被阅读0次
    public static String readFileSize(int size){
          if(size<=0){
             return "0";
          }
          final String[] units = new String[]{"B","KB","MB","GB","TB"};
          int digitGroup = (int)(Math.log10(size)/Math.log10(1024));
          double s = size/Math.pow(1024,digitGroup);
          return new DecimalFormat("#,##0.#").format(s)+units[digitGroup];
    }
    
    public static void main(String[] args) {
         String s = readFileSize(52428800);
         System.out.println(s);
    }
    

    相关文章

      网友评论

          本文标题:字节转 B KB MB GB TB

          本文链接:https://www.haomeiwen.com/subject/scspwrtx.html