Here you can find the source of formatSpaceSize(long file_size)
public static String formatSpaceSize(long file_size)
//package com.java2s; import java.text.DecimalFormat; public class Main { public final static DecimalFormat NO_DECIMAL_POINT_DF = new DecimalFormat( "0"); public final static DecimalFormat ONE_DECIMAL_POINT_DF = new DecimalFormat( "0.0"); public static String formatSpaceSize(long file_size) { if (file_size < 1024) { return file_size + "B"; } else if (file_size < 1024 * 1024) { return NO_DECIMAL_POINT_DF.format((double) file_size / 1024) + "KB"; } else if (file_size < 1024 * 1024 * 1024) { return NO_DECIMAL_POINT_DF .format((double) file_size / 1024 / 1024) + "MB"; } else {/*from www.j av a 2 s . co m*/ return ONE_DECIMAL_POINT_DF .format((double) file_size / 1024 / 1024 / 1024) + "GB"; } } }