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

doFormattingWithParsedFormat() защищенный Метод

Format rules defined in $parsedFormat array are used. Localizable symbols are replaced with elements from $symbols array, and currency placeholder is replaced with the value of $currency, if not NULL. If $number is NaN or infinite, proper localized symbol will be returned, as defined in CLDR specification.
protected doFormattingWithParsedFormat ( mixed $number, array $parsedFormat, array $symbols, string $currency = null ) : string
$number mixed Float or int, can be negative, can be NaN or infinite
$parsedFormat array An array describing format (as in $parsedFormats property)
$symbols array An array with symbols to use (as in $localeSymbols property)
$currency string Currency symbol to be inserted into formatted number (if applicable)
Результат string Formatted number. Will return string-casted version of $number if pattern is FALSE
    protected function doFormattingWithParsedFormat($number, array $parsedFormat, array $symbols, $currency = null)
    {
        if ($parsedFormat === false) {
            return (string) $number;
        }
        if (is_nan($number)) {
            return $symbols['nan'];
        }
        if (is_infinite($number)) {
            if ($number < 0) {
                return $parsedFormat['negativePrefix'] . $symbols['infinity'] . $parsedFormat['negativeSuffix'];
            } else {
                return $parsedFormat['positivePrefix'] . $symbols['infinity'] . $parsedFormat['positiveSuffix'];
            }
        }
        $isNegative = $number < 0;
        $number = abs($number * $parsedFormat['multiplier']);
        if ($parsedFormat['rounding'] > 0) {
            $number = round($number / $parsedFormat['rounding'], 0, \PHP_ROUND_HALF_EVEN) * $parsedFormat['rounding'];
        }
        if ($parsedFormat['maxDecimalDigits'] >= 0) {
            $number = round($number, $parsedFormat['maxDecimalDigits']);
        }
        $number = (string) $number;
        if (($positionOfDecimalSeparator = strpos($number, '.')) !== false) {
            $integerPart = substr($number, 0, $positionOfDecimalSeparator);
            $decimalPart = substr($number, $positionOfDecimalSeparator + 1);
        } else {
            $integerPart = $number;
            $decimalPart = '';
        }
        if ($parsedFormat['minDecimalDigits'] > strlen($decimalPart)) {
            $decimalPart = str_pad($decimalPart, $parsedFormat['minDecimalDigits'], '0');
        }
        $integerPart = str_pad($integerPart, $parsedFormat['minIntegerDigits'], '0', STR_PAD_LEFT);
        if ($parsedFormat['primaryGroupingSize'] > 0 && strlen($integerPart) > $parsedFormat['primaryGroupingSize']) {
            $primaryGroupOfIntegerPart = substr($integerPart, -$parsedFormat['primaryGroupingSize']);
            $restOfIntegerPart = substr($integerPart, 0, -$parsedFormat['primaryGroupingSize']);
            // Pad the numbers with spaces from the left, so the length of the string is a multiply of secondaryGroupingSize (and str_split() can split on equal parts)
            $padLengthToGetEvenSize = (int) ((strlen($restOfIntegerPart) + $parsedFormat['secondaryGroupingSize'] - 1) / $parsedFormat['secondaryGroupingSize']) * $parsedFormat['secondaryGroupingSize'];
            $restOfIntegerPart = str_pad($restOfIntegerPart, $padLengthToGetEvenSize, ' ', STR_PAD_LEFT);
            // Insert localized group separators between every secondary groups and primary group (using str_split() and implode())
            $secondaryGroupsOfIntegerPart = str_split($restOfIntegerPart, $parsedFormat['secondaryGroupingSize']);
            $integerPart = ltrim(implode($symbols['group'], $secondaryGroupsOfIntegerPart)) . $symbols['group'] . $primaryGroupOfIntegerPart;
        }
        if (strlen($decimalPart) > 0) {
            $decimalPart = $symbols['decimal'] . $decimalPart;
        }
        if ($isNegative) {
            $number = $parsedFormat['negativePrefix'] . $integerPart . $decimalPart . $parsedFormat['negativeSuffix'];
        } else {
            $number = $parsedFormat['positivePrefix'] . $integerPart . $decimalPart . $parsedFormat['positiveSuffix'];
        }
        $number = str_replace(['%', '‰', '-'], [$symbols['percentSign'], $symbols['perMille'], $symbols['minusSign']], $number);
        if ($currency !== null) {
            // @todo When currency is set, min / max DecimalDigits and rounding is overridden with CLDR data
            $number = str_replace('¤', $currency, $number);
        }
        return $number;
    }