This commit is contained in:
Andrew Nicols
2022-03-19 21:40:31 +08:00
2 changed files with 4 additions and 1 deletions
+2 -1
View File
@@ -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;
+2
View File
@@ -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();