package me.bell.downapp.util;
import java.text.DecimalFormat;
/**
* @Info
* @Auth Bello
* @Time 18-4-11 上午10:59
* @Ver
*/
public class FileUtils {
/**
* 文件大小数值格式化GB MB KB
*
* @param size
* @return
*/
public static String convertFileSize(long size) {
long kb = 1024;
long mb = kb * 1024;
long gb = mb * 1024;
if (size >= gb) {
return String.format("%.1f GB", (float) size / gb);
} else if (size >= mb) {
float f = (float) size / mb;
return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
} else if (size >= kb) {
float f = (float) size / kb;
return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
} else
return String.format("%d B", size);
}
/**
* 第三位显示,
* @param size
* @return
*/
public static String convertDownCount(long size){
return new DecimalFormat(",###").format(size);
}
}