zoukankan      html  css  js  c++  java
  • java B转换KB MB GB TB PB EB ZB

    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.     }  
  • 相关阅读:
    2021.3.3
    2021.3.2
    2021.3.1
    2021.2.28(每周总结)
    2021.2.27
    2021.2.26
    2021.2.25
    2021.2.23
    Redis系统学习之五大基本数据类型(List(列表))
    Redis系统学习之五大基本数据类型(String(字符串))
  • 原文地址:https://www.cnblogs.com/yaomajor/p/6085671.html
Copyright © 2011-2022 走看看