1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-26 01:36:55 +00:00

Format negative number of bytes

This commit is contained in:
M66B 2021-08-30 07:24:31 +02:00
parent 5b34f19f54
commit acfba7812b

View file

@ -1201,11 +1201,16 @@ public class Helper {
}
private static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int sign = (int) Math.signum(bytes);
bytes = Math.abs(bytes);
int unit = (si ? 1000 : 1024);
if (bytes < unit)
return sign * bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return df.format(bytes / Math.pow(unit, exp)) + " " + pre + "B";
return df.format(sign * bytes / Math.pow(unit, exp)) + " " + pre + "B";
}
static boolean isPrintableChar(char c) {