diff -uNr moodle.orig/question/type/calculated/questiontype.php moodle/question/type/calculated/questiontype.php
--- moodle.orig/question/type/calculated/questiontype.php	2008-03-11 02:14:33.000000000 +0000
+++ moodle/question/type/calculated/questiontype.php	2008-09-08 08:30:35.000000000 +0100
@@ -367,7 +367,7 @@
             $correctanswer = qtype_calculated_calculate_answer(
                  $answer->answer, $state->options->dataset, $answer->tolerance,
                  $answer->tolerancetype, $answer->correctanswerlength,
-                 $answer->correctanswerformat, $unit);
+                 $answer->correctanswerformat, $unit, 1);
            $numericalquestion->options->answers[$key]->answer = $correctanswer->answer;
         }
         $numericalquestion->questiontext = parent::substitute_variables(
@@ -1077,7 +1077,7 @@
 question_register_questiontype(new question_calculated_qtype());
 
 function qtype_calculated_calculate_answer($formula, $individualdata,
-        $tolerance, $tolerancetype, $answerlength, $answerformat='1', $unit='') {
+        $tolerance, $tolerancetype, $answerlength, $answerformat='1', $unit='', $nounits=0) {
 /// The return value has these properties:
 /// ->answer    the correct answer
 /// ->min       the lower bound for an acceptable response
@@ -1098,15 +1098,15 @@
                 $calculated->answer = $regs[1] . substr(
                         $regs[2] . '00000000000000000000000000000000000000000x',
                         0, $answerlength)
-                        . $unit;
+                        ;  //MDL-4474,MDL4901: units attached at the end 
             } else {
                 $calculated->answer .=
                         substr('.00000000000000000000000000000000000000000x',
-                        0, $answerlength + 1) . $unit;
+                        0, $answerlength + 1) ;  //MDL-4474,MDL4901: units attached at the end
             }
         } else {
             /* Attach unit */
-            $calculated->answer .= $unit;
+            //$calculated->answer .= $unit;  //MDL-4474,MDL4901: units attached at the end
         }
 
     } else if ($answer) { // Significant figures does only apply if the result is non-zero
@@ -1139,25 +1139,25 @@
             $eX = 'e'.--$p10;
             $answer *= 10;
             if (1 == $answerlength) {
-                $calculated->answer = $sign.$answer.$eX.$unit;
+                $calculated->answer = $sign.$answer.$eX;  //MDL-4474,MDL4901: units attached at the end
             } else {
                 // Attach additional zeros at the end of $answer,
                 $answer .= (1==strlen($answer) ? '.' : '')
                         . '00000000000000000000000000000000000000000x';
                 $calculated->answer = $sign
-                        .substr($answer, 0, $answerlength +1).$eX.$unit;
+                        .substr($answer, 0, $answerlength +1).$eX; //MDL-4474,MDL4901: units attached at the end
             }
         } else {
             // Stick to plain numeric format
             $answer *= "1e$p10";
             if (0.1 <= $answer / "1e$answerlength") {
-                $calculated->answer = $sign.$answer.$unit;
+                $calculated->answer = $sign.$answer; //MDL-4474,MDL4901: units attached at the end
             } else {
                 // Could be an idea to add some zeros here
                 $answer .= (ereg('^[0-9]*$', $answer) ? '.' : '')
                         . '00000000000000000000000000000000000000000x';
                 $oklen = $answerlength + ($p10 < 1 ? 2-$p10 : 1);
-                $calculated->answer = $sign.substr($answer, 0, $oklen).$unit;
+                $calculated->answer = $sign.substr($answer, 0, $oklen); //MDL-4474,MDL4901: units attached at the end
             }
         }
 
@@ -1165,6 +1165,10 @@
         $calculated->answer = 0.0;
     }
 
+    //MDL-4474, MDL4901: extra units are added here...
+    if (!$nounits) {
+      if ($calculated->answer != 0.0) $calculated->answer .= $unit;
+    }
     /// Return the result
     return $calculated;
 }
diff -uNr moodle.orig/question/type/numerical/questiontype.php moodle/question/type/numerical/questiontype.php
--- moodle.orig/question/type/numerical/questiontype.php	2008-08-29 01:16:25.000000000 +0100
+++ moodle/question/type/numerical/questiontype.php	2008-09-08 08:30:35.000000000 +0100
@@ -278,7 +278,7 @@
             return true;
         }
 
-        $response = $this->apply_unit(stripslashes($state->responses['']), $question->options->units);
+        $response = $this->apply_unit(stripslashes($state->responses['']), $question->options->units, 1);
 
         if ($response === false) {
             return false; // The student did not type a number.
@@ -395,7 +395,8 @@
      * @return float               The rawresponse with the unit taken into
      *                             account as a float.
      */
-    function apply_unit($rawresponse, $units) {
+    //MDL-4474,MDL-4901: avoid only numerical check if units are required
+    function apply_unit($rawresponse, $units, $testunits=0) {
         // Make units more useful
         $tmpunits = array();
         foreach ($units as $unit) {
@@ -422,6 +423,17 @@
 
             } else {
                 // Valid number without unit.
+
+                //MDL-4474,MDL-4901: this way default unit is checked if exists
+                if ($testunits) {
+                   if (!empty($tmpunits)) {
+                     // if there are units defined and the answer has nothing
+                     // we assume this isn't only numerical value check. Even
+                     // if the value is correct the answer is incorrect
+                     return false;
+                   }
+                }
+
                 return (float)$responseparts[1];
             }
         }
