1. public static String readableFileSize(long size) {  
  2.         if (size <= 0) {  
  3.             return "0";  
  4.         }  
  5.         final String[] units = new String[]{"B", "kB", "MB", "GB", "TB", "PB","EB","ZB"};  
  6.         int digitGroups = (int) (Math.log10(size) / Math.log10(1024));  
  7.         return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];  
  8.     }  

     

  1. public static void main(String[] args) {  
  2.         String str= "212132342412";
  3.         String str=MyCommonTool.readableFileSize(Long.parseLong(str)+'l');  
  4.         System.out.println("str="+str);                      
  5.           
  6.     }  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2022-12-23
  • 2021-11-17
  • 2021-12-24
  • 2022-12-23
  • 2022-02-17
  • 2021-11-17
相关资源
相似解决方案