打印这句 Log.d("zll","481441=="+Formatter.formatFileSize(this,481441));
结果是这样的:D/zll: 481441==481 kB
网页在线转换的结果是: 470.1572265625 KB
是不是有问题啊,不应该除以1024吗,求大佬释疑
打印这句 Log.d("zll","481441=="+Formatter.formatFileSize(this,481441));
结果是这样的:D/zll: 481441==481 kB
网页在线转换的结果是: 470.1572265625 KB
是不是有问题啊,不应该除以1024吗,求大佬释疑
public static String formatFileSize(@Nullable Context context, long sizeBytes) {
if (context == null) {
return "";
}
final BytesResult res = formatBytes(context.getResources(), sizeBytes, FLAG_SI_UNITS);
return bidiWrap(context, context.getString(com.android.internal.R.string.fileSizeSuffix,
res.value, res.units));
}
public static BytesResult formatBytes(Resources res, long sizeBytes, int flags) {
final int unit = ((flags & FLAG_IEC_UNITS) != 0) ? 1024 : 1000;
...
}
public static final int FLAG_SI_UNITS = 1 << 2;
public static final int FLAG_IEC_UNITS = 1 << 3;
因此unit = 1000;
所以 是 481 不是 470