Skip to content

Commit

Permalink
MDL-26505 rounding problem in quiz_save_best_grade.
Browse files Browse the repository at this point in the history
Note I cheated and slipped in a fix for another instance of MDL-21811 too, since I noticed it at the same time.
  • Loading branch information
timhunt committed Feb 18, 2011
1 parent 0af9124 commit 49b2521
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/index.php
Expand Up @@ -147,7 +147,7 @@
$feedback = '';
if ($quiz->grade && !is_null($bestgrade)) {
if ($alloptions->scores) {
$grade = "$bestgrade / $quiz->grade";
$grade = round($bestgrade, $quiz->decimalpoints) . ' / ' . $quiz->grade;
}
if ($alloptions->overallfeedback) {
$feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/lib.php
Expand Up @@ -186,7 +186,7 @@ function quiz_get_best_grade($quiz, $userid) {

// Need to detect errors/no result, without catching 0 scores.
if (is_numeric($grade)) {
return round($grade, $quiz->decimalpoints);
return $grade + 0;
} else {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/locallib.php
Expand Up @@ -429,7 +429,7 @@ function quiz_save_best_grade($quiz, $userid = null) {

// Calculate the best grade
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);

// Save the best grade in the database
if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
Expand Down
6 changes: 3 additions & 3 deletions mod/quiz/view.php
Expand Up @@ -267,11 +267,11 @@
}

// Ouside the if because we may be showing feedback but not grades.
$attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz);
$attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz, false);

if ($gradecolumn) {
if ($attemptoptions->scores && $attempt->timefinish > 0) {
$formattedgrade = $attemptgrade;
$formattedgrade = round($attemptgrade, $quiz->decimalpoints);
// highlight the highest grade if appropriate
if ($overallstats && $numattempts > 1 && !is_null($mygrade) && $attemptgrade == $mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) {
$table->rowclass[$attempt->attempt] = 'bestrow';
Expand Down Expand Up @@ -313,7 +313,7 @@
if ($available && $moreattempts) {
$a = new stdClass;
$a->method = quiz_get_grading_option_name($quiz->grademethod);
$a->mygrade = $mygrade;
$a->mygrade = round($mygrade, $quiz->decimalpoints);
$a->quizgrade = $quiz->grade;
$resultinfo .= print_heading(get_string('gradesofar', 'quiz', $a), '', 2, 'main', true);
} else {
Expand Down

0 comments on commit 49b2521

Please sign in to comment.