From a3b7dd338289d5f90a0750aa82017efe2dcd2485 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 22 May 2024 15:09:40 +0200 Subject: [Util] Fix formatBytes unit overflow; make work for negative values --- src/main/java/org/openslx/util/Util.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') 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] ); } -- cgit v1.2.3-55-g7522