Here you can find the source of getFileSizeFormat(String total_size)
public static String getFileSizeFormat(String total_size)
//package com.java2s; import java.text.*; public class Main { public static String getFileSizeFormat(String total_size) { double file_size = Double.parseDouble(total_size); String file_size_nm = ""; DecimalFormat f2 = new DecimalFormat("0.00"); if (1023 < file_size) { file_size = file_size / 1024; file_size_nm = f2.format(file_size) + "KB"; } else {// ww w.jav a 2 s .c o m file_size_nm = file_size + "byte"; } if (1023 < file_size) { file_size = file_size / 1024; file_size_nm = f2.format(file_size) + "MB"; } if (1023 < file_size) { file_size = file_size / 1024; file_size_nm = f2.format(file_size) + "GB"; } if (1023 < file_size) { file_size = file_size / 1024; file_size_nm = f2.format(file_size) + "TB"; } return file_size_nm; } }