From be1bb80efa8223ace8e70b5024286bbdd8501ec4 Mon Sep 17 00:00:00 2001 From: Pierre Pichet Date: Thu, 17 Dec 2009 21:45:10 +0000 Subject: [PATCH] MDL-3282 , MDL-4595 error in numerical with comma . More number formats are allowed --- question/type/numerical/questiontype.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index 63cbc5bef7..9978c76aa1 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -632,9 +632,15 @@ class question_numerical_qtype extends question_shortanswer_qtype { $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 (preg_match('~^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$~', -- 2.39.5