Convert size in long to 1KB, or MB - Android java.lang

Android examples for java.lang:long

Description

Convert size in long to 1KB, or MB

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main{

    public static String sizeConvert(long size) {
        if (size <= 1024) {
            return "1Kb";
        } else if (size > 1024 && size < 1024 * 1024) {
            return size / 1024 + "Kb";
        } else {/*from   www  .j a v  a 2  s.c om*/
            return size / 1024 / 1024 + "M";
        }
    }

}

Related Tutorials