Here you can find the source of toMB(long bytes)
public static String toMB(long bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String toMB(long bytes) { if (bytes < 0) { return "n/a"; }//from w w w . j a va2s.c o m if (bytes > 1024 * 1024 * 1024) { return "" + (bytes / 1024 / 1024 / 1024) + "G"; } else if (bytes > 1024 * 1024) { return "" + (bytes / 1024 / 1024) + "M"; } else if (bytes > 1024) { return "" + (bytes / 1024) + "K"; } else { return "" + bytes + "B"; } } }