Merge branch 'MDL-33480' of git://github.com/stronk7/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 4 Jun 2012 08:59:49 +0000 (16:59 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 4 Jun 2012 08:59:49 +0000 (16:59 +0800)
lib/evalmath/evalmath.class.php
lib/tests/mathslib_test.php

index aa5539f..9d9c7d6 100644 (file)
@@ -107,7 +107,7 @@ class EvalMath {
         'sin','sinh','arcsin','asin','arcsinh','asinh',
         'cos','cosh','arccos','acos','arccosh','acosh',
         'tan','tanh','arctan','atan','arctanh','atanh',
-        'sqrt','abs','ln','log','exp','floor','ceil','round');
+        'sqrt','abs','ln','log','exp','floor','ceil');
 
     var $fc = array( // calc functions emulation
         'average'=>array(-1), 'max'=>array(-1),  'min'=>array(-1),
index 4c56eed..1df41fe 100644 (file)
@@ -142,6 +142,9 @@ class mathsslib_testcase extends basic_testcase {
     }
 
     public function test_rounding_function() {
+        // Rounding to the default number of decimal places
+        // The default == 0
+
         $formula = new calc_formula('=round(2.5)');
         $this->assertEquals($formula->evaluate(), 3);
 
@@ -196,6 +199,19 @@ class mathsslib_testcase extends basic_testcase {
         $formula = new calc_formula('=floor(-2.5)');
         $this->assertEquals($formula->evaluate(), -3);
 
+        // Rounding to an explicit number of decimal places
+
+        $formula = new calc_formula('=round(2.5, 1)');
+        $this->assertEquals($formula->evaluate(), 2.5);
+
+        $formula = new calc_formula('=round(2.5, 0)');
+        $this->assertEquals($formula->evaluate(), 3);
+
+        $formula = new calc_formula('=round(1.2345, 2)');
+        $this->assertEquals($formula->evaluate(), 1.23);
+
+        $formula = new calc_formula('=round(123.456, -1)');
+        $this->assertEquals($formula->evaluate(), 120);
     }
 
     public function test_scientific_notation() {