I'm trying to do an Calculation of my Project were I need to do Division and Multiplication to get my Ans but getting an error "Uncaught DivisionByZeroError: Division by zero". my Code and Error as shown in Screenshots
$total_plates=$row['s_tps'];
$total_a_kg=$row['s_kg'];
$plates_per_kg=$row['s_pkg'];
$remaing_kg=(1000/$plates_per_kg)*$total_plates;
echo "$remaing_kg";[![enter image description here][1]][1]
CodePudding user response:
In the following line,
$remaing_kg=(1000/$plates_per_kg)*$total_plates;
if '$plates_per_kg' value is 0, then this error will occur
Or "0", or null, or false, or array() or anything that intval would return 0 for.
Edit: Thanks for the comment @msbit
CodePudding user response:
Code is okay
$total_plates=$row['s_tps'];
$total_a_kg=$row['s_kg'];
$plates_per_kg=$row['s_pkg'];
$pkg=1000;
$remaing_kg=($pkg/$plates_per_kg)*$total_plates;
Their is problem in your database find out target column of $plates_per_kg and see that any row contain 0 if you find 0 in any row then this error will occur so remove that zero. or while you creating DB set an restriction to not take 0. Thank You.