Permalink
Browse files

MDL-3282 , MDL-4595 error in numerical with comma . More number forma…

…ts are allowed.

merged from HEAD
  • Loading branch information...
1 parent 3ae036b commit efed05fd2555454dffe4660513c03276a9783538 @ppichet ppichet committed Dec 17, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 question/type/numerical/questiontype.php
@@ -366,9 +366,16 @@ function apply_unit($rawresponse, $units) {
$tmpunits[$unit->unit] = $unit->multiplier;
}
// remove spaces and normalise decimal places.
+ $rawresponse = trim($rawresponse) ;
$search = array(' ', ',');
- $replace = array('', '.');
- $rawresponse = str_replace($search, $replace, trim($rawresponse));
+ // test if a . is present or there are multiple , (i.e. 2,456,789 ) so that we don't need spaces and ,
+ if ( strpos($rawresponse,'.' ) !== false || substr_count($rawresponse,',') > 1 ) {
+ $replace = array('', '');
+ }else { // remove spaces and normalise , to a . .
+ $replace = array('', '.');
+ }
+ $rawresponse = str_replace($search, $replace, $rawresponse);
+
// Apply any unit that is present.
if (ereg('^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$',

0 comments on commit efed05f

Please sign in to comment.