Browse Source

Use bccomp to compare floats instead of '>=' fixes BT#15438

Julio Montoya 6 years ago
parent
commit
457e2fe725
2 changed files with 6 additions and 4 deletions
  1. 1 0
      composer.json
  2. 5 4
      main/inc/lib/exercise.lib.php

+ 1 - 0
composer.json

@@ -45,6 +45,7 @@
         "ext-libxml": "*",
         "ext-dom": "*",
         "ext-fileinfo": "*",
+        "ext-bcmath": "*",
         "twig/twig": "1.*",
         "twig/extensions": "~1.0",
         "doctrine/orm": "~2.4",

+ 5 - 4
main/inc/lib/exercise.lib.php

@@ -4654,14 +4654,16 @@ EOT;
 
                 $score = [];
                 if ($show_results) {
+                    $compareResult = bccomp($my_total_score, $my_total_weight, 3);
+                    $scorePassed = $compareResult === 1 || $compareResult === 0;
+
                     $score = [
                         'result' => self::show_score(
                             $my_total_score,
                             $my_total_weight,
-                            false,
-                            true
+                            false
                         ),
-                        'pass' => $my_total_score >= $my_total_weight ? true : false,
+                        'pass' => $scorePassed,
                         'score' => $my_total_score,
                         'weight' => $my_total_weight,
                         'comments' => $comnt,
@@ -4683,7 +4685,6 @@ EOT;
                 $question_content = '';
                 if ($show_results) {
                     $question_content = '<div class="question_row_answer">';
-
                     if ($showQuestionScore == false) {
                         $score = [];
                     }