Reputation: 29
Getting two errors with this code.
Warning: A non-numeric value encountered in
Warning: Division by zero in...NAN%
<ul class="list list-icons list-icons-style-3 list-primary">
<li><i class="fa fa-calculator"></i> <strong>Entries:</strong> <?php echo $show_enter; ?> - <strong>Attended:</strong> <?php echo $show_attended; ?> - <strong>Percent Turnout:</strong>
<?php
if($percent = ($show_attended/$show_enter)*100){
echo round_out($percent) . '%';
}else{
echo '%';
}
?></li>
</ul>
Upvotes: 1
Views: 218
Reputation: 6359
This issue occurs when you try to divide a number by zero. Because divide any number by zero is undefined.
Here $show_enter
has 0 value. That's the problem. I don't know where $show_enter
is coming from, So you need to debug $show_enter
.
But in your system Is there any possibilities $show_enter
to have 0 value, Then you need to fix this calculation issue by using condition.
<ul class="list list-icons list-icons-style-3 list-primary">
<li><i class="fa fa-calculator"></i> <strong>Entries:</strong> <?php echo $show_enter; ?> - <strong>Attended:</strong> <?php echo $show_attended; ?> - <strong>Percent Turnout:</strong>
<?php
if(!empty($show_enter)){
echo round_out(($show_attended/$show_enter)*100) . '%';
}else{
echo '%';
}
?></li>
</ul>
Upvotes: 2