Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.*; public class Main { public static String formatToMegaBytes(long bytes) { double megaBytes = bytes / 1048576.0; if (megaBytes < 1) return new DecimalFormat("0.0").format(megaBytes); return new DecimalFormat("#.0").format(megaBytes); } }