diff --git a/lib/form/float.php b/lib/form/float.php index 8f375c2b986..e1685f207de 100644 --- a/lib/form/float.php +++ b/lib/form/float.php @@ -175,12 +175,18 @@ class MoodleQuickForm_float extends MoodleQuickForm_text { */ private function format_float($value) { if (is_numeric($value)) { - if ($value > 0) { - $decimals = strlen($value) - strlen(floor($value)) - 1; + // We want to keep trailing zeros after the decimal point if there is any. + // Therefore we cannot just call format_float() and pass -1 as the number of decimal points. + $pieces = preg_split('/E/i', $value); // In case it is in the scientific format. + $decimalpos = strpos($pieces[0], '.'); + if ($decimalpos !== false) { + $decimalpart = substr($pieces[0], $decimalpos + 1); + $decimals = strlen($decimalpart); } else { - $decimals = strlen($value) - strlen(ceil($value)) - 1; + $decimals = 0; } - $value = format_float($value, $decimals); + $pieces[0] = format_float($pieces[0], $decimals); + $value = implode('E', $pieces); } return $value; }