Here you can find the source of formatSize(double size)
public static String formatSize(double size)
//package com.java2s; //License from project: Open Source License public class Main { private static final String[] SIZE_UNITS = { "B", "K", "M", "G", "T" }; public static String formatSize(double size) { int i;// www . j a v a2s . c om for (i = 0; size >= 1024 && i < 4; i++) { size /= 1024; } return (Math.round(size * 100.0) / 100.0) + " " + SIZE_UNITS[i]; } }