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