[TASK] Sync CMS Fluid with Flow Fluid 1.1 (part1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / NumberViewHelper.php
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
14 /**
15 * Formats a number with custom precision, decimal point and grouped thousands.
16 * @see http://www.php.net/manual/en/function.number-format.php
17 *
18 * = Examples =
19 *
20 * <code title="Defaults">
21 * <f:format.number>423423.234</f:format.number>
22 * </code>
23 * <output>
24 * 423,423.20
25 * </output>
26 *
27 * <code title="With all parameters">
28 * <f:format.number decimals="1" decimalSeparator="," thousandsSeparator=".">423423.234</f:format.number>
29 * </code>
30 * <output>
31 * 423.423,2
32 * </output>
33 *
34 * @api
35 */
36 class NumberViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
37
38 /**
39 * Format the numeric value as a number with grouped thousands, decimal point and
40 * precision.
41 *
42 * @param integer $decimals The number of digits after the decimal point
43 * @param string $decimalSeparator The decimal point character
44 * @param string $thousandsSeparator The character for grouping the thousand digits
45 * @return string The formatted number
46 * @api
47 */
48 public function render($decimals = 2, $decimalSeparator = '.', $thousandsSeparator = ',') {
49 $stringToFormat = $this->renderChildren();
50 return number_format($stringToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
51 }
52 }
53
54 ?>