Skip to content

Commit ad016b6

Browse files
committed
Better fix to “Division by zero” Error alexjustesen#1326
1 parent 8a95cba commit ad016b6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/helpers.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ function toBits(float $size, int $precision = 4): float
2727
if (! function_exists('percentChange')) {
2828
function percentChange(float $dividend, float $divisor, int $precision = 0): string
2929
{
30-
if ($dividend === 0 || $divisor === 0) {
30+
try {
31+
$quotient = $dividend / $divisor;
32+
} catch (DivisionByZeroError $e) {
3133
return 0;
3234
}
3335

@@ -73,7 +75,7 @@ function json_validate($data)
7375
{
7476
if (! empty($data)) {
7577
return is_string($data) &&
76-
is_array(json_decode($data, true)) ? true : false;
78+
is_array(json_decode($data, true)) ? true : false;
7779
}
7880

7981
return false;

0 commit comments

Comments
 (0)