mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-67151 forms: Support for the scientific format in the float element
This commit is contained in:
parent
ac384d1d88
commit
2bfc16ad2a
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user