Problem to split variables in PHP

Asked

Viewed 100 times

1

I’m having trouble with a php page. Whenever I put the following code to do the division of two variables stored in arrays

$dj_cv_at[percentual][$i] = ($dj_cv_at[concluida_c_imp_total][$i] / $dj_cv_at[concluida_total][$i]) * 100;

As a result the page stops working properly.

This only happens when I put the split operator. With the other operators the code runs perfectly.

  • gives some error, appears? is problem with division by zero? wrong decimal places? could detail better the problem.

  • Thanks, pal, I got it. The problem was related to the division of 0 by 0. To solve the problem I did so: if ($dj_cv_at[concluida_c_imp_total][$i] == 0){ $dj_cv_at[percentage][$i] = 0; } Else {$dj_cv_at[percentage][$i] =($dj_cv_at[concluida_c_imp_total][$i] / $dj_cv_at[concluida_total][$i]) * 100;}

1 answer

0

After analysis I found that the problem was related to division of 0. So to solve this I did the following:

if ($dj_cv_at[concluida_c_imp_total][$i] == 0){ 
$dj_cv_at[percentual][$i] = 0; } 
else {$dj_cv_at[percentual][$i] =($dj_cv_at[concluida_c_imp_total][$i] 
/ $dj_cv_at[concluida_total][$i]) * 100;} 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.