Here you can find the source of getSpaceMessage(final double bytes)
public static String getSpaceMessage(final double bytes)
//package com.java2s; import java.text.DecimalFormat; public class Main { private static final long KILO = 1024; private static final long MEGA = KILO * KILO; private static final long GIGA = KILO * MEGA; private static final long TERA = KILO * GIGA; private static final DecimalFormat SPACE_FORMAT = new DecimalFormat("##0.#"); public static String getSpaceMessage(final double bytes) { if (bytes < (KILO * 0.8)) { return bytes + "B"; }//from w w w .j ava 2s. c o m if (bytes < (MEGA * 0.8)) { final double kilos = bytes / KILO; return SPACE_FORMAT.format(kilos) + "kB"; } if (bytes < (GIGA * 0.8)) { final double megas = bytes / MEGA; return SPACE_FORMAT.format(megas) + "MB"; } if (bytes < (TERA * 0.8)) { final double gigas = bytes / GIGA; return SPACE_FORMAT.format(gigas) + "GB"; } final double teras = bytes / TERA; return SPACE_FORMAT.format(teras) + "TB"; } }