CurrencyFormatter
Formats currency amounts using locale-specific patterns.
- Full name:
\CommerceGuys\Intl\Formatter\CurrencyFormatter
- This class implements:
\CommerceGuys\Intl\Formatter\CurrencyFormatterInterface
Properties
numberFormatRepository
The number format repository.
currencyRepository
The currency repository.
defaultLocale
The default locale.
numberFormats
The loaded number formats.
currencies
The loaded currencies.
defaultOptions
The default options.
Methods
__construct
Creates a CurrencyFormatter instance.
public __construct(\CommerceGuys\Intl\NumberFormat\NumberFormatRepositoryInterface $numberFormatRepository, \CommerceGuys\Intl\Currency\CurrencyRepositoryInterface $currencyRepository, array $defaultOptions = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormatRepository |
\CommerceGuys\Intl\NumberFormat\NumberFormatRepositoryInterface | The number format repository. |
$currencyRepository |
\CommerceGuys\Intl\Currency\CurrencyRepositoryInterface | The currency repository. |
$defaultOptions |
array | The default options. |
Throws:
format
Formats a currency amount.
Parameters:
Parameter | Type | Description |
---|---|---|
$number |
mixed | The number. |
$currencyCode |
mixed | The currency code. |
$options |
array | The formatting options. |
Return Value:
The formatted number.
parse
Parses a formatted currency amount.
Parameters:
Parameter | Type | Description |
---|---|---|
$number |
mixed | The formatted number. |
$currencyCode |
mixed | The currency code. |
$options |
array | The parsing options. |
Return Value:
The parsed number or FALSE on error.
getNumberFormat
Gets the number format for the provided locale.
Parameters:
Parameter | Type | Description |
---|---|---|
$locale |
string | The locale. |
getCurrency
Gets the currency for the provided currency code and locale.
Parameters:
Parameter | Type | Description |
---|---|---|
$currencyCode |
string | The currency code. |
$locale |
string | The locale. |
getAvailablePatterns
{@inheritdoc}
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat |
validateOptions
Validates the provided options.
Ensures the absence of unknown keys, correct data types and values.
Parameters:
Parameter | Type | Description |
---|---|---|
$options |
array | The options. |
Throws:
getLocalizedSymbols
{@inheritdoc}
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat |
Inherited methods
formatNumber
Formats the number according to the number format.
protected formatNumber(string $number, \CommerceGuys\Intl\NumberFormat\NumberFormat $numberFormat, array $options = []): string
Parameters:
Parameter | Type | Description |
---|---|---|
$number |
string | The number. |
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
$options |
array |
Return Value:
The formatted number.
localizeNumber
Localizes the number according to the number format.
protected localizeNumber(string $number, \CommerceGuys\Intl\NumberFormat\NumberFormat $numberFormat): string
Both the digits and the symbols are replaced with their localized equivalents.
Parameters:
Parameter | Type | Description |
---|---|---|
$number |
string | The number. |
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
Return Value:
The localized number.
See Also:
- http://cldr.unicode.org/translation/number-symbols -
parseNumber
Parses the number according to the number format.
protected parseNumber(string $number, \CommerceGuys\Intl\NumberFormat\NumberFormat $numberFormat): string
Both the digits and the symbols are replaced with their non-localized equivalents.
Parameters:
Parameter | Type | Description |
---|---|---|
$number |
string | The number. |
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
Return Value:
The localized number.
getParsedPattern
Gets the pattern for the provided number format.
protected getParsedPattern(\CommerceGuys\Intl\NumberFormat\NumberFormat $numberFormat, string $style): \CommerceGuys\Intl\Formatter\ParsedPattern
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
$style |
string | The formatter style. |
getAvailablePatterns
Gets the available patterns for the provided number format.
protected getAvailablePatterns(\CommerceGuys\Intl\NumberFormat\NumberFormat $numberFormat): string[]
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
Return Value:
The patterns, keyed by style.
getLocalizedSymbols
Gets the localized symbols for the provided number format.
Used to localize the number in localizeNumber().
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$numberFormat |
\CommerceGuys\Intl\NumberFormat\NumberFormat | The number format. |
Automatically generated on 2025-03-18