‪TYPO3CMS  9.5
NumberViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20 
48 class ‪NumberViewHelper extends AbstractViewHelper
49 {
50  use CompileWithRenderStatic;
51 
57  protected ‪$escapeChildren = false;
58 
64  public function ‪initializeArguments()
65  {
66  $this->registerArgument('decimals', 'int', 'The number of digits after the decimal point', false, '2');
67  $this->registerArgument('decimalSeparator', 'string', 'The decimal point character', false, '.');
68  $this->registerArgument('thousandsSeparator', 'string', 'The character for grouping the thousand digits', false, ',');
69  }
70 
81  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
82  {
83  $decimals = $arguments['decimals'];
84  $decimalSeparator = $arguments['decimalSeparator'];
85  $thousandsSeparator = $arguments['thousandsSeparator'];
86 
87  $stringToFormat = $renderChildrenClosure();
88  return number_format((float)$stringToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
89  }
90 }
‪TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper\$escapeChildren
‪bool $escapeChildren
Definition: NumberViewHelper.php:55
‪TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: NumberViewHelper.php:79
‪TYPO3\CMS\Fluid\ViewHelpers\Format
Definition: AbstractEncodingViewHelper.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper\initializeArguments
‪initializeArguments()
Definition: NumberViewHelper.php:62
‪TYPO3\CMS\Fluid\ViewHelpers\Format\NumberViewHelper
Definition: NumberViewHelper.php:49