一些简单的数学不能在我的助手中工作

时间:2016-07-27 12:04:09

标签: ruby-on-rails

我有一个grade功能:

def grade(submission)
score_counter = 0
total_score = submission.test.questions.size

#the scoring logic is here

return (score_counter/total_score)*100
end

目的是返回百分比,但在我看来显示的所有内容都是0。如果我只是尝试单独返回score_countertotal_score,它们会显示正确的值。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您需要将值更改为浮动

$query = "SELECT * FROM assignments WHERE course_id=1";
        $result1 = mysqli_query($conn, $query);
        if (mysqli_num_rows($result1) != 0) {
            $i = 0; //-------------->INITIALIZE THE VARIABLE
        while ($row=mysqli_fetch_assoc($result1)) {
          echo '<th colspan="'.$my_values[$i].'">'.$row['assignment_name'].'</th>';
          $i++; //----------------> INCREMENT THE VARIABLE
        }
      }