java B转换KB MB GB TB PB EB ZB
- public static String readableFileSize(long size) {
- if (size <= 0) {
- return "0";
- }
- final String[] units = new String[]{"B", "kB", "MB", "GB", "TB", "PB","EB","ZB"};
- int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
- return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
- }
- public static void main(String[] args) {
- String str= "212132342412";
- String str=MyCommonTool.readableFileSize(Long.parseLong(str)+'l');
- System.out.println("str="+str);
- }