support custom number of decimals in currency modifier
authormutec <mysterycode@mysterycode.de>
Sat, 26 Jun 2021 17:17:46 +0000 (19:17 +0200)
committermutec <mysterycode@mysterycode.de>
Sun, 11 Jul 2021 15:14:51 +0000 (17:14 +0200)
wcfsetup/install/files/lib/system/template/plugin/CurrencyModifierTemplatePlugin.class.php

index 878f169130816c7302021cdb6f0f998b7d28b4e9..db6478559c6b218a380deb32d852a4b54dc12f8a 100644 (file)
@@ -7,9 +7,13 @@ use wcf\system\WCF;
 
 /**
  * Formats a currency value.
+ * The default number of decimals is `2`.
+ *
+ * Defining the number of decimals is available since version 5.4.
  *
  * Usage:
  *  {$float|currency}
+ *  {$float|currency:$numberOfDecimals}
  *
  * @author  Marcel Werk
  * @copyright   2001-2019 WoltLab GmbH
@@ -23,9 +27,11 @@ class CurrencyModifierTemplatePlugin implements IModifierTemplatePlugin
      */
     public function execute($tagArgs, TemplateEngine $tplObj)
     {
+        $decimals = \intval($tagArgs[1] ?? 2);
+
         return \number_format(
-            \round($tagArgs[0], 2),
-            2,
+            \round($tagArgs[0], $decimals),
+            $decimals,
             WCF::getLanguage()->get('wcf.global.decimalPoint'),
             WCF::getLanguage()->get('wcf.global.thousandsSeparator')
         );