Java tutorial
//package com.java2s; public class Main { public static String fileSizeFormat(long size) { float mbSize = size / 1000f / 1000f; if (mbSize < 1000f) { return String.format("%d MB ", Math.round(mbSize)); } else { float gSize = mbSize / 1000f; if (gSize < 1000f) { return String.format("%d G ", Math.round(gSize)); } else { float TSize = gSize / 1000f; return String.format("%d T ", Math.round(TSize)); } } } }