Java Size Format formatSize(double fileSize)

Here you can find the source of formatSize(double fileSize)

Description

format Size

License

Open Source License

Declaration

public static String formatSize(double fileSize) 

Method Source Code

//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;
    }
}

Related

  1. formatFileSize(Long sizeBytes)
  2. formatFilesizeGB(long filesize, int fractionDigits)
  3. formatGameSize(int size)
  4. formatMemorySize(long size)
  5. formatPartSize(int size, NumberFormat format)
  6. formatSize(double size)
  7. formatSize(int size)
  8. formatSize(long bytes)
  9. formatSize(long bytes)