From aecb339307580896130b932900f0c56b8b000398 Mon Sep 17 00:00:00 2001 From: Kyle Temkin Date: Thu, 22 Sep 2011 12:11:49 +0100 Subject: [PATCH] MDL-28202 qtype_calculated fix edge case in the rounding code. --- question/type/calculated/questiontype.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 6be1bbe1365..4c450d4b24b 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -1893,6 +1893,12 @@ function qtype_calculated_calculate_answer($formula, $individualdata, // ... and have the answer rounded of to the correct length $answer = round($answer, $answerlength); + //if we rounded up to 1.0, place the answer back into 0.[1-9][0-9]* format + if ($answer >= 1) { + ++$p10; + $answer /= 10; + } + // Have the answer written on a suitable format, // Either scientific or plain numeric if (-2 > $p10 || 4 < $p10) {