From f9bec1f2e79b00c8a5bc4a31eff5b4769e4d1a24 Mon Sep 17 00:00:00 2001 From: mindforge Date: Mon, 26 Sep 2005 09:18:22 +0000 Subject: [PATCH] Another improvement on regrading. The code thought that grading for a question changed if the grade was like 1/3. The precision in the database is different than the newly calculated grade, so now we round both values to 5 decimal places, which should fix this problem. --- mod/quiz/locallib.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index a8ce958f498..21bcd4841e4 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1531,10 +1531,13 @@ function quiz_regrade_question_in_attempt($question, $attempt, $quiz=false, $ver $attempt)) { $verbose && notify("Couldn't regrade state #{$state->id}!"); } - if ((float)$replaystate->grade != (float)$states[$j]->grade) { - $changed++; + // We need rounding here because grades in the DB get truncated + // e.g. 0.33333 != 0.3333333, but we want them to be equal here + if (round((float)$replaystate->grade, 5) != round((float)$states[$j]->grade, 5)) { + $changed++; } + $replaystate->id = $states[$j]->id; $replaystate->update = true; quiz_save_question_session($question, $replaystate);