Java tutorial
//package com.java2s; import java.text.NumberFormat; public class Main { /** * Converts a length of bytes to MB. * * @param bytes * The bytes to convert * @return A string representation of the MB */ public static String convertBytesToMB(long bytes) { double result = (double) bytes / 1000 / 1000; NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setGroupingUsed(false); return nf.format(result) + " MB"; } }