Skip to content

CurrencyFormatter

The currency formatter will format numbers according to a given format and a given currency symbol

class CurrencyFormatter extends DecimalFormatter implements ITranslator

ExtendsDecimalFormatter
ImplementsITranslator
Since1.0.0
SourceTranslation/CurrencyFormatter.php
MethodDescription
getContext(): ?ContextRetrieve the current application context.
getCurrencyCode(): stringReturns the iso code of the currency which should be used when formatting.
getCurrencySymbol(): stringReturns the currency symbol which should be used when formatting.
initialize(Context $context, array<string, mixed> $parameters = []): voidInitialize this Translator.
localeChanged(QuioteLocale $newLocale): voidThis method gets called by the translation manager when the default locale has been changed.
reset(): voidReset per-request locale state for worker compatibility.
setFractionDigits(int $count): voidSets the amount of fractional digits to be shown.
translate(mixed $message, string $domain, ?QuioteLocale $locale = null): stringTranslates a message into the defined language.

final public function getContext(): ?Context

Retrieve the current application context.

Returns ?Context — The current Context instance.

public function getCurrencyCode(): string

Returns the iso code of the currency which should be used when formatting.

Returns string — The currency iso code.

public function getCurrencySymbol(): string

Returns the currency symbol which should be used when formatting.

Returns string — The currency symbol

public function initialize(Context $context, array<string, mixed> $parameters = []): void

Initialize this Translator.

An associative array of initialization parameters

ParameterTypeDescription
$contextContextThe current application context.
$parametersarray``<``string``, ``mixed``>An associative array of initialization parameters

public function localeChanged(QuioteLocale $newLocale): void

This method gets called by the translation manager when the default locale has been changed.

The new default locale.

ParameterTypeDescription
$newLocaleQuioteLocaleThe new default locale.

public function reset(): void

Reset per-request locale state for worker compatibility.

context, customFormat, currencyCode and translationDomain are configured once from initialize() parameters and never restored afterward — clearing them here would silently lose the configured currency/format for every subsequent request. Only locale (and the derived format fields cleared by parent::reset(), which localeChanged() always recomputes) are per-request.

public function setFractionDigits(int $count): void

Sets the amount of fractional digits to be shown.

The amount of digits.

ParameterTypeDescription
$countintThe amount of digits.

public function translate(mixed $message, string $domain, ?QuioteLocale $locale = null): string

Translates a message into the defined language.

The locale to which the message should be translated.

ParameterTypeDescription
$messagemixedThe message to be translated.
$domainstringThe domain of the message.
$locale?QuioteLocaleThe locale to which the message should be translated.

Returns string — The translated message.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
formatCurrency()DecimalFormatterFormats the given currency and returns the formatted result.
formatNumber()DecimalFormatterFormats the given number and returns the formatted result.
getFormat()DecimalFormatterReturns the format which is currently used to format numbers.
getRoundingMode()DecimalFormatterReturns the rounding mode.
getRoundingModeFromString()DecimalFormatterMaps a string rounding mode definition to the rounding mode constants.
parse()DecimalFormatterParses a string into float or int.
setFormat()DecimalFormatterSets the format to be used for formatting numbers.
setRoundingMode()DecimalFormatterSets the rounding mode.