TYPO3  7.6
CurrencyViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
17 
48 {
59  public function render($currencySign = '', $decimalSeparator = ',', $thousandsSeparator = '.', $prependCurrency = false, $separateCurrency = true, $decimals = 2)
60  {
61  return static::renderStatic(
62  array(
63  'currencySign' => $currencySign,
64  'decimalSeparator' => $decimalSeparator,
65  'thousandsSeparator' => $thousandsSeparator,
66  'prependCurrency' => $prependCurrency,
67  'separateCurrency' => $separateCurrency,
68  'decimals' => $decimals
69  ),
71  $this->renderingContext
72  );
73  }
74 
83  {
84  $currencySign = $arguments['currencySign'];
85  $decimalSeparator = $arguments['decimalSeparator'];
86  $thousandsSeparator = $arguments['thousandsSeparator'];
87  $prependCurrency = $arguments['prependCurrency'];
88  $separateCurrency = $arguments['separateCurrency'];
89  $decimals = $arguments['decimals'];
90 
91  $floatToFormat = $renderChildrenClosure();
92  if (empty($floatToFormat)) {
93  $floatToFormat = 0.0;
94  } else {
95  $floatToFormat = floatval($floatToFormat);
96  }
97  $output = number_format($floatToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
98  if ($currencySign !== '') {
99  $currencySeparator = $separateCurrency ? ' ' : '';
100  if ($prependCurrency === true) {
101  $output = $currencySign . $currencySeparator . $output;
102  } else {
103  $output = $output . $currencySeparator . $currencySign;
104  }
105  }
106  return $output;
107  }
108 }