Skip to content
Browse files

MDL-28202 qtype_calculated fix edge case in the rounding code.

  • Loading branch information...
1 parent 136fa79 commit 18d81bdb3c45b8cbe0a33f81ace28c4a3d0f8e54 @ktemkin ktemkin committed with timhunt Sep 22, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 question/type/calculated/questiontype.php
View
6 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) {

0 comments on commit 18d81bd

Please sign in to comment.
Something went wrong with that request. Please try again.