我得到零除错误这个功能。我该如何解决?
function percent($liked,$total_voting){
$liked = (int)$liked;
$total_voting = (int)$total_voting;
return ceil(($liked/$total_voting)*100);
答案 0 :(得分:1)
这应该适合你:
(如果$total_voting
为零,则进行测试,在这种情况下返回false)
function percent($liked, $total_voting) {
if($total_voting == 0)
return false;
$liked = (int)$liked;
$total_voting = (int)$total_voting;
return ceil(($liked/$total_voting)*100);
}