MDL-53140 qtype_numerical: Localised decimal separator bug fix

- Support decimal separator when it is not . or ,
- Also make sure that we don't remove . when thousandsseparator is .
- Display the answer fields in the editing form in the localised format
This commit is contained in:
Shamim Rezaie
2019-05-01 12:10:32 +10:00
parent 688c803550
commit 326bb5474a
2 changed files with 7 additions and 2 deletions
@@ -210,6 +210,11 @@ class qtype_numerical_edit_form extends question_edit_form {
unset($this->_form->_defaultValues["tolerance[{$key}]"]);
$question->tolerance[$key] = $answer->tolerance;
if (is_numeric($question->answer[$key])) {
$question->answer[$key] = format_float($question->answer[$key], strlen($question->answer[$key]), true, true);
}
$key++;
}
+2 -2
View File
@@ -553,7 +553,7 @@ class qtype_numerical_answer_processor {
}
/**
* @return book If the student's response contains a '.' or a ',' that
* @return bool If the student's response contains a '.' or a ',' that
* matches the thousands separator in the current locale. In this case, the
* parsing in apply_unit can give a result that the student did not expect.
*/
@@ -651,7 +651,7 @@ class qtype_numerical_answer_processor {
if (strpos($response, '.') !== false || substr_count($response, ',') > 1) {
$response = str_replace(',', '', $response);
} else {
$response = str_replace(',', '.', $response);
$response = str_replace([$this->thousandssep, $this->decsep, ','], ['', '.', '.'], $response);
}
$regex = '[+-]?(?:\d+(?:\\.\d*)?|\\.\d+)(?:e[-+]?\d+)?';