Java Fraction Format format(float totalNumberOfFreeBytes)

Here you can find the source of format(float totalNumberOfFreeBytes)

Description

format

License

Open Source License

Declaration

public static String format(float totalNumberOfFreeBytes) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 cnfree.// ww w .  j  av a 2  s . c  o m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  cnfree  - initial API and implementation
 *******************************************************************************/

import java.text.NumberFormat;

public class Main {
    public static String format(float totalNumberOfFreeBytes) {
        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(1);
        format.setMinimumFractionDigits(0);
        if (totalNumberOfFreeBytes < 1024)
            return format.format(totalNumberOfFreeBytes) + " Bytes";
        totalNumberOfFreeBytes = totalNumberOfFreeBytes / 1024;
        if (totalNumberOfFreeBytes < 1024)
            return format.format(totalNumberOfFreeBytes) + " KB";
        totalNumberOfFreeBytes = totalNumberOfFreeBytes / 1024;
        if (totalNumberOfFreeBytes < 1024)
            return format.format(totalNumberOfFreeBytes) + " MB";
        totalNumberOfFreeBytes = totalNumberOfFreeBytes / 1024;
        if (totalNumberOfFreeBytes < 1024)
            return format.format(totalNumberOfFreeBytes) + " GB";
        return null;
    }
}

Related

  1. format(final NumberFormat fmt, final double val)
  2. format(float f)
  3. format(Float f)
  4. format(float num)
  5. format(float number, int bitCount)
  6. format(float value)
  7. format(NumberFormat nf, float number, float defaultValue)
  8. format0(Double d)
  9. format2Double(Double amount)