Neos\Flow\I18n\Formatter\NumberFormatter::formatCurrencyNumber PHP Метод

formatCurrencyNumber() публичный Метод

Currency symbol provided will be inserted into formatted number string. Note: currently length is not used in currencyFormats from CLDR. But it's defined in the specification, so we support it here.
public formatCurrencyNumber ( mixed $number, Locale $locale, string $currency, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT ) : string
$number mixed Float or int, can be negative, can be NaN or infinite
$locale Neos\Flow\I18n\Locale
$currency string Currency symbol (or name)
$formatLength string One of NumbersReader FORMAT_LENGTH constants
Результат string Formatted number. Will return string-casted version of $number if there is no pattern for given $locale / $formatLength
    public function formatCurrencyNumber($number, Locale $locale, $currency, $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
    {
        NumbersReader::validateFormatLength($formatLength);
        return $this->doFormattingWithParsedFormat($number, $this->numbersReader->parseFormatFromCldr($locale, NumbersReader::FORMAT_TYPE_CURRENCY, $formatLength), $this->numbersReader->getLocalizedSymbolsForLocale($locale), $currency);
    }

Usage Example

 /**
  * @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;
 }
All Usage Examples Of Neos\Flow\I18n\Formatter\NumberFormatter::formatCurrencyNumber