Przeglądaj źródła

Use bccomp to compare float requires php-bcmath extension BT#15438

Julio Montoya 6 lat temu
rodzic
commit
6e36fbcd2c
1 zmienionych plików z 6 dodań i 1 usunięć
  1. 6 1
      main/exercise/exercise_show.php

+ 6 - 1
main/exercise/exercise_show.php

@@ -910,13 +910,18 @@ foreach ($questionList as $questionId) {
 
     $score = [];
     if ($show_results) {
+        $scorePassed = $my_total_score >= $my_total_weight;
+        if (function_exists('bccomp')) {
+            $compareResult = bccomp($my_total_score, $my_total_weight, 3);
+            $scorePassed = $compareResult === 1 || $compareResult === 0;
+        }
         $score['result'] = ExerciseLib::show_score(
             $my_total_score,
             $my_total_weight,
             false,
             false
         );
-        $score['pass'] = $my_total_score >= $my_total_weight ? true : false;
+        $score['pass'] = $scorePassed;
         $score['type'] = $answerType;
         $score['score'] = $my_total_score;
         $score['weight'] = $my_total_weight;