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.     }  
  • 相关阅读:
    Ruby自学笔记(二)— Ruby的一些基础知识
    Ruby自学笔记(一)— 基本概况
    Tomcat基础教程(四)
    Excel导入
    构建API
    序列化
    图片上传(练习)
    发邮件
    发短信
    Excel表导出
  • 原文地址:https://www.cnblogs.com/yaomajor/p/6085671.html
Copyright © 2011-2022 走看看