Merge branch 'MDL-74270' of https://github.com/timhunt/moodle
This commit is contained in:
+2
-1
@@ -8767,8 +8767,9 @@ function format_float($float, $decimalpoints=1, $localized=true, $stripzeros=fal
|
||||
}
|
||||
|
||||
$result = number_format($float, $decimalpoints, $separator, '');
|
||||
if ($stripzeros) {
|
||||
if ($stripzeros && $decimalpoints > 0) {
|
||||
// Remove zeros and final dot if not needed.
|
||||
// However, only do this if there is a decimal point!
|
||||
$result = preg_replace('~(' . preg_quote($separator, '~') . ')?0+$~', '', $result);
|
||||
}
|
||||
return $result;
|
||||
|
||||
@@ -2340,6 +2340,8 @@ EOF;
|
||||
// Option to strip ending zeros after rounding.
|
||||
$this->assertEquals('5.43', format_float(5.43, 5, true, true));
|
||||
$this->assertEquals('5', format_float(5.0001, 3, true, true));
|
||||
$this->assertEquals('100', format_float(100, 2, true, true));
|
||||
$this->assertEquals('100', format_float(100, 0, true, true));
|
||||
|
||||
// Tests with a localised decimal separator.
|
||||
$this->define_local_decimal_separator();
|
||||
|
||||
Reference in New Issue
Block a user