From f46aa4d36bf4e0c87fc077c16e56bedd7cdf6cf4 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 8 Nov 2023 13:54:41 +0100 Subject: [PATCH] Implicitly round float values to 2 decimal places See https://www.woltlab.com/community/thread/302362-statistics-are-too-precise-reduce-to-two-decimals/ --- .../template/plugin/PluralFunctionTemplatePlugin.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wcfsetup/install/files/lib/system/template/plugin/PluralFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/PluralFunctionTemplatePlugin.class.php index 5b57962628..d32d16138f 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/PluralFunctionTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/PluralFunctionTemplatePlugin.class.php @@ -54,6 +54,12 @@ final class PluralFunctionTemplatePlugin implements IFunctionTemplatePlugin $value = $tagArgs['value']; if (\is_countable($value)) { $value = \count($value); + } else if (\is_numeric($value) && \floor($value) != $value) { + // ICU represents fractional values with up to 3 decimal places + // which differs from the behavior in `StringUtil::formatNumeric`. + // The weak comparison of the rounded value allows us to detect + // decimal places while leaving integer values as-is. + $value = \round($value, 2); } // handle numeric attributes -- 2.20.1