diff options
author | Simon Rettberg | 2024-05-22 15:09:40 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-05-22 15:09:40 +0200 |
commit | a3b7dd338289d5f90a0750aa82017efe2dcd2485 (patch) | |
tree | 3456c208403698598a57424a799748672453e130 /src | |
parent | NanoHTTPD: Add test for ChunkedInputStream (diff) | |
download | master-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.java | 7 |
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] ); } |