Here you can find the source of format(float totalNumberOfFreeBytes)
public static String format(float totalNumberOfFreeBytes)
//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; } }