Permalink
Browse files

Improved number rounding for grades fix (Merged from MOODLE_15_STABLE

  • Loading branch information...
1 parent f29e785 commit 9db357c08bbabb5ace100df3e0a5abaa26d9e21d patrickslee committed Oct 2, 2005
Showing with 9 additions and 4 deletions.
  1. +9 −4 mod/quiz/questionlib.php
@@ -321,9 +321,14 @@ function quiz_save_question_session(&$question, &$state) {
// Set the legacy answer field
$state->answer = isset($state->responses['']) ? $state->responses[''] : '';
+ // Round long grade
+ if (strlen($state->grade) > 10 && floatval($state->grade)) {
+ $state->grade = strval(round($state->grade,10-1-strlen(floor($state->grade))));
+ }
+
// Round long raw_grade
- if (strlen($state->raw_grade) > 10 && floatval($state->raw_grade) < 1) {
- $state->raw_grade = strval(round($state->raw_grade,2));
+ if (strlen($state->raw_grade) > 10 && floatval($state->raw_grade)) {
+ $state->raw_grade = strval(round($state->raw_grade,10-1-strlen(floor($state->raw_grade))));
}
// Save the state
@@ -664,8 +669,8 @@ function quiz_process_responses(&$question, &$state, $action, $cmoptions, &$atte
}
$attempt->timemodified = $action->timestamp;
// Round long sumgrades
- if (strlen($attempt->sumgrades) > 10 && floatval($attempt->sumgrades) < 1) {
- $attempt->sumgrades = strval(round($attempt->sumgrades,2));
+ if (strlen($attempt->sumgrades) > 10 && floatval($attempt->sumgrades)) {
+ $attempt->sumgrades = strval(round($attempt->sumgrades,10-1-strlen(floor($state->sumgrades))));
}
return true;

0 comments on commit 9db357c

Please sign in to comment.