PHP Class Neos\Flow\I18n\Formatter\NumberFormatter

Inheritance: implements Neos\Flow\I18n\Formatter\FormatterInterface
Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$numbersReader Neos\Flow\I18n\Cldr\Reader\NumbersReader

Public Methods

Method Description
format ( mixed $value, Locale $locale, array $styleProperties = [] ) : string Formats provided value using optional style properties
formatCurrencyNumber ( mixed $number, Locale $locale, string $currency, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT ) : string Formats number with format string for currency defined in CLDR for particular locale.
formatDecimalNumber ( mixed $number, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT ) : string Formats number with format string for decimal numbers defined in CLDR for particular locale.
formatNumberWithCustomPattern ( mixed $number, string $format, Locale $locale ) : string Returns number formatted by custom format, string provided in parameter.
formatPercentNumber ( mixed $number, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT ) : string Formats number with format string for percentage defined in CLDR for particular locale.
injectNumbersReader ( NumbersReader $numbersReader ) : void

Protected Methods

Method Description
doFormattingWithParsedFormat ( mixed $number, array $parsedFormat, array $symbols, string $currency = null ) : string Formats provided float or integer.

Method Details

doFormattingWithParsedFormat() protected method

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)
return string Formatted number. Will return string-casted version of $number if pattern is FALSE

format() public method

Formats provided value using optional style properties
public format ( mixed $value, Locale $locale, array $styleProperties = [] ) : string
$value mixed Formatter-specific variable to format (can be integer, \DateTime, etc)
$locale Neos\Flow\I18n\Locale Locale to use
$styleProperties array Integer-indexed array of formatter-specific style properties (can be empty)
return string String representation of $value provided, or (string)$value

formatCurrencyNumber() public method

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
return string Formatted number. Will return string-casted version of $number if there is no pattern for given $locale / $formatLength

formatDecimalNumber() public method

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
return string Formatted number. Will return string-casted version of $number if there is no pattern for given $locale / $formatLength

formatNumberWithCustomPattern() public method

Format must obey syntax defined in CLDR specification, excluding unimplemented features (see documentation for this class). Format is remembered in this classes cache and won't be parsed again for some time.
public formatNumberWithCustomPattern ( mixed $number, string $format, Locale $locale ) : string
$number mixed Float or int, can be negative, can be NaN or infinite
$format string Format string
$locale Neos\Flow\I18n\Locale A locale used for finding symbols array
return string Formatted number. Will return string-casted version of $number if pattern is not valid / supported

formatPercentNumber() public method

Note: currently length is not used in percentFormats from CLDR. But it's defined in the specification, so we support it here.
public formatPercentNumber ( 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
return string Formatted number. Will return string-casted version of $number if there is no pattern for given $locale / $formatLength

injectNumbersReader() public method

public injectNumbersReader ( NumbersReader $numbersReader ) : void
$numbersReader Neos\Flow\I18n\Cldr\Reader\NumbersReader
return void

Property Details

$numbersReader protected property

protected NumbersReader,Neos\Flow\I18n\Cldr\Reader $numbersReader
return Neos\Flow\I18n\Cldr\Reader\NumbersReader