Java tutorial
//package com.java2s; import java.text.DecimalFormat; public class Main { public static String getMemoryData(long total) { String dataText = "0"; DecimalFormat df = new DecimalFormat("###.00"); if (total == -1) { return dataText; } else if (total < 1024) { dataText = "<1MB"; } else if (total < 1024 * 1024) { dataText = df.format(total / 1024f) + "MB"; } return dataText; } }