public static String byteCalculation(String bytes) {
String retFormat = "0";
Double size = Double.parseDouble(bytes);
int unit = 1024;
DecimalFormat df = null;
String[] s = {"B", "KB", "MB", "GB", "TB", "PB"};
if (!bytes.equals("0")) {
if (size < unit) {
df = new DecimalFormat("#,###.###");
double t = size / unit;
return String.valueOf(df.format(t)) + " " + s[1];
} else {
int idx = (int) Math.floor(Math.log(size) / Math.log(unit));
df = new DecimalFormat("#,###");
double ret = ((size / Math.pow(unit, Math.floor(idx))));
retFormat = df.format(ret) + " " + s[idx];
}
} else {
retFormat += " " + s[0];
}
return retFormat;
}
'android' 카테고리의 다른 글
뷰페이저 스와이프해서 프래그먼튼 이동 막기 (0) | 2019.09.30 |
---|---|
안드로이드 로그 레벨 색상 (0) | 2019.08.12 |
urlEncode, urlDecode (0) | 2019.04.08 |
Base64Encode, Decode (0) | 2019.04.08 |
SharedPreferences (0) | 2019.04.08 |