Skip to content

Commit

Permalink
Fix exercise result when using float values BT#16683
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jan 31, 2020
1 parent 431f88e commit 19d3425
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main/inc/lib/exercise.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,7 @@ public static function convertScoreToPlatformSetting($score, $weight)
$minNote = api_get_setting('exercise_min_score');

if ($maxNote != '' && $minNote != '') {
if (!empty($weight) && intval($weight) != 0) {
if (!empty($weight) && (float) $weight !== 0) {
$score = $minNote + ($maxNote - $minNote) * $score / $weight;
} else {
$score = $minNote;
Expand Down Expand Up @@ -2839,6 +2839,7 @@ public static function show_score(
$percentage = float_format($percentage, 1);
$score = float_format($score, 1);
$weight = float_format($weight, 1);

if ($roundValues) {
$whole = floor($percentage); // 1
$fraction = $percentage - $whole; // .25
Expand Down Expand Up @@ -2877,6 +2878,7 @@ public static function show_score(
if ($hidePercentageSign) {
$percentageSign = '';
}

$html = $percentage."$percentageSign ($score / $weight)";
if ($show_only_percentage) {
$html = $percentage.$percentageSign;
Expand All @@ -2891,9 +2893,10 @@ public static function show_score(
$html = $scoreBasedInModel;
}

// Ignore other formats and use the configuratio['exercise_score_format'] value
// Ignore other formats and use the configuration['exercise_score_format'] value
// But also keep the round values settings.
$format = api_get_configuration_value('exercise_score_format');

if (!empty($format)) {
$html = ScoreDisplay::instance()->display_score([$score, $weight], $format);
}
Expand Down

0 comments on commit 19d3425

Please sign in to comment.