Here you can find the source of toMemoryString(double bytes)
public static String toMemoryString(double bytes)
//package com.java2s; //License from project: LGPL public class Main { public static String toMemoryString(double bytes) { double display = bytes; if (display < 1024) return display + "b"; display /= 1024.0;/*from w w w . ja va2s. c o m*/ if (display < 1024) return String.format("%-1.1f", display) + "kb"; display /= 1024.0; if (display < 1024) return String.format("%-1.1f", display) + "mb"; display /= 1024.0; return String.format("%-1.1f", display) + "gb"; } }