Catch division by zero

This commit is contained in:
James Cole 2024-06-01 05:36:21 +02:00
parent 119b9920a6
commit c067d6aab0
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80

View File

@ -185,7 +185,7 @@ class BudgetLimitController extends Controller
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($start, $end);
// left per day:
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
$array['left_per_day'] = 0 === bccomp('0',$array['days_left']) ? bcadd($array['spent'], $array['amount']) : bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
// left per day formatted.
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);