summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2024-05-22 15:09:40 +0200
committerSimon Rettberg2024-05-22 15:09:40 +0200
commita3b7dd338289d5f90a0750aa82017efe2dcd2485 (patch)
tree3456c208403698598a57424a799748672453e130 /src
parentNanoHTTPD: Add test for ChunkedInputStream (diff)
downloadmaster-sync-shared-a3b7dd338289d5f90a0750aa82017efe2dcd2485.tar.gz
master-sync-shared-a3b7dd338289d5f90a0750aa82017efe2dcd2485.tar.xz
master-sync-shared-a3b7dd338289d5f90a0750aa82017efe2dcd2485.zip
[Util] Fix formatBytes unit overflow; make work for negative values
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/util/Util.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/util/Util.java b/src/main/java/org/openslx/util/Util.java
index 2ebd4e1..e425083 100644
--- a/src/main/java/org/openslx/util/Util.java
+++ b/src/main/java/org/openslx/util/Util.java
@@ -155,11 +155,12 @@ public class Util
public static String formatBytes( double val )
{
int unit = 0;
- while ( val > 1024 ) {
+ while ( Math.abs(val) > 1024 ) {
val /= 1024;
unit++;
- if (unit >= UNITS.length)
- break;
+ }
+ if (unit >= UNITS.length) {
+ unit = UNITS.length - 1;
}
return String.format( "%.1f %s", val, UNITS[unit] );
}