diff --git a/app/Helpers/Number.php b/app/Helpers/Number.php index 4ad6fc51e..c565eebe3 100644 --- a/app/Helpers/Number.php +++ b/app/Helpers/Number.php @@ -35,6 +35,10 @@ public static function bitsToHuman(int|float $bits, int $precision = 0, ?int $ma { $units = ['B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb']; + if ($bits === 0) { + return '0 B'; + } + for ($i = 0; ($bits / 1000) > 0.99 && ($i < count($units) - 1); $i++) { $bits /= 1000; } @@ -51,6 +55,10 @@ public static function toBitRate(int|float $bits, int $precision = 0, ?int $maxP { $units = ['Bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps']; + if ($bits === 0) { + return '0 B'; + } + for ($i = 0; ($bits / 1000) > 0.99 && ($i < count($units) - 1); $i++) { $bits /= 1000; } diff --git a/app/helpers.php b/app/helpers.php index 8684022ce..b70141cb9 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -27,6 +27,10 @@ function toBits(float $size, int $precision = 4): float if (! function_exists('percentChange')) { function percentChange(float $dividend, float $divisor, int $precision = 0): string { + if ($dividend === 0 || $divisor === 0) { + return 0; + } + $quotient = ($dividend - $divisor) / $divisor; return number_format(round($quotient * 100, $precision), $precision);