Here you can find the source of getFileSizeFormat(double inputvalue)
public static String getFileSizeFormat(double inputvalue)
//package com.java2s; //License from project: Apache License public class Main { public static String getFileSizeFormat(double inputvalue) { String outputvalue = "0"; if (inputvalue >= 1024 * 1024) { outputvalue = formatFloat("###,##0.0", inputvalue / (1024 * 1024)) + "M"; } else if (inputvalue >= 1024) { outputvalue = formatFloat("###,##0.0", inputvalue / 1024) + "K"; } else {/*from w w w. j ava 2 s . c o m*/ outputvalue = formatFloat("###,##0", inputvalue) + "Bytes"; } return outputvalue; } public static String formatFloat(String format, double f) { StringBuffer formatString = new StringBuffer(format); java.text.DecimalFormat df = new java.text.DecimalFormat(formatString.toString()); return df.format(f); } }