NumberFormatter
class NumberFormatter implements FormatterInterface (View source)
Formatter for numbers.
Properties
protected NumbersReader | $numbersReader | ||
protected CurrencyReader | $currencyReader |
Methods
Returns number formatted by custom format, string provided in parameter.
Formats number with format string for decimal numbers defined in CLDR for particular locale.
Formats number with format string for percentage defined in CLDR for particular locale.
Formats number with format string for currency defined in CLDR for particular locale.
Formats provided float or integer.
Details
void
injectNumbersReader(NumbersReader $numbersReader)
No description
void
injectCurrencyReader(CurrencyReader $currencyReader)
No description
string
format(mixed $value, Locale $locale, array $styleProperties = [])
Formats provided value using optional style properties
string
formatNumberWithCustomPattern(mixed $number, string $format, Locale $locale)
Returns number formatted by custom format, string provided in parameter.
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.
string
formatDecimalNumber(mixed $number, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
Formats number with format string for decimal numbers defined in CLDR for particular locale.
Note: currently length is not used in decimalFormats from CLDR. But it's defined in the specification, so we support it here.
string
formatPercentNumber(mixed $number, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT)
Formats number with format string for percentage defined in CLDR for particular locale.
Note: currently length is not used in percentFormats from CLDR. But it's defined in the specification, so we support it here.
string
formatCurrencyNumber(mixed $number, Locale $locale, string $currency, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, string $currencyCode = null)
Formats number with format string for currency defined in CLDR for particular locale.
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.
protected string
doFormattingWithParsedFormat(mixed $number, array $parsedFormat, array $symbols, string $currency = null)
Formats provided float or integer.
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.