Here you can find the source of formatSize(double fileSize)
public static String formatSize(double fileSize)
//package com.java2s; /**/*w w w. ja v a 2s . com*/ * Created on Aug 9, 2004 * * Copyright 2005 by Arysys Technologies (P) Ltd., * #3,Shop line, * Sasmira Marg, * Worli,Mumbai 400 025 * India * * All rights reserved. * * This software is the confidential and proprietary information * of Arysys Technologies (P) Ltd. ("Confidential Information"). * You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Arysys Technologies (P) Ltd. * */ import java.text.DecimalFormat; public class Main { public static String formatSize(double fileSize) { DecimalFormat onePlace = new DecimalFormat("0.0"); String result = ""; result = "<h1>" + (int) fileSize + "</h1> bytes"; double length = 0.0; if (fileSize > 1024) { length = fileSize / 1024; result = "<h1>" + onePlace.format(length) + "</h1> kilo bytes"; } if (fileSize > 1048576) { length = fileSize / 1048576; result = "<h1>" + onePlace.format(length) + "</h1> mega bytes"; } if (fileSize > 1073741824) { length = fileSize / 1073741824; result = "<h1>" + onePlace.format(length) + "</h1> giga bytes"; } return result; } }