/** * @param mixed $stringToFormat * @param mixed $locale string or boolean or \TYPO3\Flow\I18n\Locale * @param string $currencySign * * @throws \TYPO3\Fluid\Core\ViewHelper\Exception\InvalidVariableException * @return string */ protected function renderUsingLocale($stringToFormat, $locale, $currencySign) { if ($locale instanceof I18n\Locale) { $useLocale = $locale; } elseif (is_string($locale)) { try { $useLocale = new I18n\Locale($locale); } catch (I18n\Exception $exception) { throw new InvalidVariableException('"' . $locale . '" is not a valid locale identifier.', 1342610148, $exception); } } else { $useLocale = $this->localizationService->getConfiguration()->getCurrentLocale(); } return $this->numberFormatter->formatCurrencyNumber($stringToFormat, $useLocale, $currencySign); }
/** * @param string $currencySign (optional) The currency sign, eg $ or €. * @param string $decimalSeparator (optional) The separator for the decimal point. * @param string $thousandsSeparator (optional) The thousands separator. * * @throws InvalidVariableException * @return string the formatted amount. * @throws ViewHelperException * @api */ public function render($currencySign = '', $decimalSeparator = ',', $thousandsSeparator = '.') { $stringToFormat = $this->renderChildren(); $useLocale = $this->getLocale(); if ($useLocale !== NULL) { if ($currencySign === '') { throw new InvalidVariableException('Using the Locale requires a currencySign.', 1326378320); } try { $output = $this->numberFormatter->formatCurrencyNumber($stringToFormat, $useLocale, $currencySign); } catch (I18nException $exception) { throw new ViewHelperException($exception->getMessage(), 1382350428, $exception); } } else { $output = number_format((double) $stringToFormat, 2, $decimalSeparator, $thousandsSeparator); if ($currencySign !== '') { $output .= ' ' . $currencySign; } } return $output; }