private void convertCcrl(long v) {
String[] s = new String[]{"Bytes", "KB", "MB", "GB", "TB", "PB"};
int e = (int) Math.floor(Math.log(b.getCcrl()) / Math.log(1024));
// 取值 如 5.36KB 中的5.36
long val = v / Math.pow(1024, e);
// 计量单位 如KB
String unit = s[e];
return b;
}
通过取对数的方法来计算出 单位在数组中对应的索引。