src/i18n/Formatter.php
protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
    {
        $formatter = new NumberFormatter($this->getLocale(), $style);

        // set text attributes
        foreach ($this->numberFormatterTextOptions as $name => $attribute) {
            $formatter->setTextAttribute($name, $attribute);
        }
        foreach ($textOptions as $name => $attribute) {
            $formatter->setTextAttribute($name, $attribute);
        }

        // set attributes
        foreach ($this->numberFormatterOptions as $name => $value) {
            $formatter->setAttribute($name, $value);
        }
        foreach ($options as $name => $value) {
            $formatter->setAttribute($name, $value);
        }
        if ($decimals !== null) {
            $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
            $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
        }

        // set symbols
        if ($this->decimalSeparator !== null) {
            $formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
        }
        if ($this->thousandSeparator !== null) {
            $formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
            $formatter->setSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
        }
        foreach ($this->numberFormatterSymbols as $name => $symbol) {
            $formatter->setSymbol($name, $symbol);
        }

        return $formatter;
    }
protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
    {
        $formatter = new NumberFormatter($this->getLocale(), $style);

        // set text attributes
        foreach ($this->numberFormatterTextOptions as $name => $attribute) {
            $formatter->setTextAttribute($name, $attribute);
        }
        foreach ($textOptions as $name => $attribute) {
            $formatter->setTextAttribute($name, $attribute);
        }

        // set attributes
        foreach ($this->numberFormatterOptions as $name => $value) {
            $formatter->setAttribute($name, $value);
        }
        foreach ($options as $name => $value) {
            $formatter->setAttribute($name, $value);
        }
        if ($decimals !== null) {
            $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
            $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
        }

        // set symbols
        if ($this->decimalSeparator !== null) {
            $formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
        }
        if ($this->thousandSeparator !== null) {
            $formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
            $formatter->setSymbol(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $this->thousandSeparator);
        }
        foreach ($this->numberFormatterSymbols as $name => $symbol) {
            $formatter->setSymbol($name, $symbol);
        }

        return $formatter;
    }
protected function createNumberFormatter ( $ style , $ decimals = null , $ options = [ ] , $ textOptions = [ ] ) { $ formatter = new NumberFormatter ( $ this -> getLocale ( ) , $ style ) ; // set text attributes foreach ( $ this -> numberFormatterTextOptions as $ name => $ attribute ) { $ formatter -> setTextAttribute ( $ name , $ attribute ) ; } foreach ( $ textOptions as $ name => $ attribute ) { $ formatter -> setTextAttribute ( $ name , $ attribute ) ; } // set attributes foreach ( $ this -> numberFormatterOptions as $ name => $ value ) { $ formatter -> setAttribute ( $ name , $ value ) ; } foreach ( $ options as $ name => $ value ) { $ formatter -> setAttribute ( $ name , $ value ) ; } if ( $ decimals !== null ) { $ formatter -> setAttribute ( NumberFormatter :: MAX_FRACTION_DIGITS , $ decimals ) ; $ formatter -> setAttribute ( NumberFormatter :: MIN_FRACTION_DIGITS , $ decimals ) ; } // set symbols if ( $ this -> decimalSeparator !== null ) { $ formatter -> setSymbol ( NumberFormatter :: DECIMAL_SEPARATOR_SYMBOL , $ this -> decimalSeparator ) ; } if ( $ this -> thousandSeparator !== null ) { $ formatter -> setSymbol ( NumberFormatter :: GROUPING_SEPARATOR_SYMBOL , $ this -> thousandSeparator ) ; $ formatter -> setSymbol ( NumberFormatter :: MONETARY_GROUPING_SEPARATOR_SYMBOL , $ this -> thousandSeparator ) ; } foreach ( $ this -> numberFormatterSymbols as $ name => $ symbol ) { $ formatter -> setSymbol ( $ name , $ symbol ) ; } return $ formatter ; }
Creates a number formatter based on the given type and format.

You may override this method to create a number formatter based on patterns.

@param int $style the type of the number formatter.
Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, ::SPELLOUT, ::ORDINAL
::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE
@param int $decimals the number of digits after the decimal point.
@param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
@return NumberFormatter the created formatter instance
Creates a number formatter based on the given type and format .