Java tutorial
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import android.content.Context; public class Main { public static String getFileSizeDescription(Context context, long bytes) { String value = ""; if (bytes < 1000) { value = (int) bytes + "B"; } else if (bytes < 1000000) { value = Math.round(bytes / 1000.0) + "K"; } else if (bytes < 1000000000) { DecimalFormat df = new DecimalFormat("#0.0"); value = df.format(bytes / 1000000.0) + "M"; } else { DecimalFormat df = new DecimalFormat("#0.00"); value = df.format(bytes / 1000000000.0) + "G"; } return value; } }