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

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

Note: currently length is not used in decimalFormats from CLDR. But it's defined in the specification, so we support it here.
public formatDecimalNumber ( mixed $number, Locale $locale, 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
$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 formatDecimalNumber($number, Locale $locale, $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
    {
        NumbersReader::validateFormatLength($formatLength);
        return $this->doFormattingWithParsedFormat($number, $this->numbersReader->parseFormatFromCldr($locale, NumbersReader::FORMAT_TYPE_DECIMAL, $formatLength), $this->numbersReader->getLocalizedSymbolsForLocale($locale));
    }

Usage Example

 /**
  * Format the numeric value as a number with grouped thousands, decimal point and
  * precision.
  *
  * @param int $decimals The number of digits after the decimal point
  * @param string $decimalSeparator The decimal point character
  * @param string $thousandsSeparator The character for grouping the thousand digits
  * @param string $localeFormatLength Format length if locale set in $forceLocale. Must be one of Neos\Flow\I18n\Cldr\Reader\NumbersReader::FORMAT_LENGTH_*'s constants.
  * @return string The formatted number
  * @api
  * @throws ViewHelperException
  */
 public function render($decimals = 2, $decimalSeparator = '.', $thousandsSeparator = ',', $localeFormatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
 {
     $stringToFormat = $this->renderChildren();
     $useLocale = $this->getLocale();
     if ($useLocale !== null) {
         try {
             $output = $this->numberFormatter->formatDecimalNumber($stringToFormat, $useLocale, $localeFormatLength);
         } catch (I18nException $exception) {
             throw new ViewHelperException($exception->getMessage(), 1382351148, $exception);
         }
     } else {
         $output = number_format((double) $stringToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
     }
     return $output;
 }