// Need to detect errors/no result, without catching 0 scores.
if (is_numeric($grade)) {
- return round($grade,$quiz->decimalpoints);
+ return round($grade, $quiz->decimalpoints);
} else {
return NULL;
}
* @param object $quiz the quiz object. Only the fields grade, sumgrades and decimalpoints are used.
* @return float the rescaled grade.
*/
-function quiz_rescale_grade($rawgrade, $quiz) {
+function quiz_rescale_grade($rawgrade, $quiz, $round = true) {
if ($quiz->sumgrades) {
- return round($rawgrade*$quiz->grade/$quiz->sumgrades, $quiz->decimalpoints);
+ $grade = $rawgrade * $quiz->grade / $quiz->sumgrades;
+ if ($round) {
+ $grade = round($grade, $quiz->decimalpoints);
+ }
} else {
- return 0;
+ $grade = 0;
}
+ return $grade;
}
/**
// Grades columns.
if ($showgrades) {
if ($attempt->timefinish) {
- $grade = round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints);
+ $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
if (!$download) {
$row[] = '<a href="review.php?q='.$quiz->id.'&attempt='.$attempt->attempt.'">'.$grade.'</a>';
} else {