Class FormatMoneyHelper
Responsibility - format money by Intl
extension or by locale formatting conventions or by explicit or default arguments.
- Formatting processed by Intl
extension if installed or by \number_format()
and \localeconv()
fallback.
- Possibility to define default decimal points value to not define it every time using FormatMoney()
call.
- Possibility to define default currency value to not define it every time using FormatMoney()
call.
- Possibility to define argument to create Intl
money formatter instance in every call or globally by default setters in parent class.
- Possibility to define any argument for number_format()
and \localeconv()
fallback in every call or globally by default setters in parent class.
- If there is used formatting fallback and no locale formatting conventions are defined, system locale settings is automatically configured by request language and request locale and by system locale settings are defined locale formatting conventions.
- Fallback result string always returned in response encoding, in UTF-8 by default.
-
MvcCore\Ext\Views\Helpers\AbstractHelper
implements
MvcCore\Ext\Views\Helpers\IHelper
-
MvcCore\Ext\Views\Helpers\InternationalizedHelper
-
MvcCore\Ext\Views\Helpers\FormatNumberHelper
-
MvcCore\Ext\Views\Helpers\FormatMoneyHelper
Namespace: MvcCore\Ext\Views\Helpers
See:
http://php.net/manual/en/numberformatter.create.php
See:
http://php.net/manual/en/numberformatter.formatcurrency.php
See:
http://php.net/manual/en/numberformatter.setattribute.php
See:
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute
See:
http://php.net/manual/en/function.number-format.php
See:
http://php.net/manual/en/function.localeconv.php
Located at ext-view-helper-formatmoney/src/MvcCore/Ext/Views/Helpers/FormatMoneyHelper.php
Methods summary
public
MvcCore\Ext\Views\Helpers\FormatMoneyHelper
|
#
SetDefaultCurrency( string $defaultCurrency )
Set default currency to not define third param every time in FormatMoney() function.
The 3-letter ISO 4217 currency code indicating the currency to use.
This property setter is used only for Intl extension formatting,
not for fallback by \number_format() and \localeconv() .
Set default currency to not define third param every time in FormatMoney() function.
The 3-letter ISO 4217 currency code indicating the currency to use.
This property setter is used only for Intl extension formatting,
not for fallback by \number_format() and \localeconv() .
Parameters
Returns
|
public
string
|
#
FormatMoney( integer|float|string $number = NULL, integer|null $decimalsCount = NULL, string|null $currency = NULL )
Parameters
- $number
- The number being formatted.
- $decimalsCount
Optional, numerics count after decimal point.
If NULL , there is used Intl localized formatter
default value for money, usually two - 2 .
If NULL for fallback number_format() , there is used
system locale settings and if there are used default
locale conventions for formatting - usually for en_US two - 2
- $currency
- Optional, 3-letter ISO 4217 currency code indicating the currency to use.
Returns
string
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/numberformatter.formatcurrency.php
http://php.net/manual/en/numberformatter.setattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute
http://php.net/manual/en/function.number-format.php
http://php.net/manual/en/function.localeconv.php
|
protected
string
|
#
formatByIntlMoneyFormatter( integer|float $valueToFormat = 0.0, integer|null $decimalsCount = NULL, string|null $currency = NULL )
Format money by Intl extension formatter. If no international three chars currency
symbol is provided, there is used currency symbol from localized Intl formatter instance.
Format money by Intl extension formatter. If no international three chars currency
symbol is provided, there is used currency symbol from localized Intl formatter instance.
Parameters
- $valueToFormat
- Numeric value to format.
- $decimalsCount
Optional, numerics count after decimal point,
If NULL , there is used Intl localized formatter
default value for money, usually two - 2 .
- $currency
Optional, 3-letter ISO 4217 currency code
indicating the currency to use.
Returns
string
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/numberformatter.formatcurrency.php
|
protected
string
|
#
fallbackFormatByLocaleConventions( integer|float $valueToFormat = 0.0, integer|null $decimalsCount = NULL )
Fallback formatting by PHP \number_format() and by system locale formatting conventions.
If there was not possible to define system locale formatting conventions, there are used
default formatting conventions, usually for en_US .
Fallback formatting by PHP \number_format() and by system locale formatting conventions.
If there was not possible to define system locale formatting conventions, there are used
default formatting conventions, usually for en_US .
Parameters
- $valueToFormat
- The number being formatted.
- $decimalsCount
Optional, numerics count after decimal point for number_format() ,
If NULL , there is used system locale settings and if there are
no locale system settings, there are used default locale conventions
for formatting - usually for en_US two - 2 .
Returns
string
See
http://php.net/manual/en/function.localeconv.php
http://php.net/manual/en/function.number-format.php
|
Methods inherited from MvcCore\Ext\Views\Helpers\FormatNumberHelper
FormatNumber(),
SetDefaultDecimalsCount(),
SetDefaultLocaleConventions(),
SetIntlDefaultAttributes(),
SetIntlDefaultPattern(),
SetIntlDefaultStyle(),
SetIntlDefaultTextAttributes(),
SetLocaleConventions(),
fallbackFormatByNumberFormat(),
formatByIntlNumberFormatter(),
getIntlNumberFormatter(),
setUpLocaleConventions()
|
Properties summary
protected static
MvcCore\Ext\Views\Helpers\FormatMoneyHelper
|
$instance
If this static property is set - helper is possible
to configure as singleton before it's used for first time.
Example:
\MvcCore\Ext\View\Helpers\FormatMoneyHelper::GetInstance()
If this static property is set - helper is possible
to configure as singleton before it's used for first time.
Example:
\MvcCore\Ext\View\Helpers\FormatMoneyHelper::GetInstance()
|
|
protected
string|null
|
$defaultCurrency
Default currency to not define third param every time in FormatMoney() function.
The 3-letter ISO 4217 currency code indicating the currency to use.
This property is used only for Intl extension formatting,
not for fallback by \number_format() and \localeconv() .
Default currency to not define third param every time in FormatMoney() function.
The 3-letter ISO 4217 currency code indicating the currency to use.
This property is used only for Intl extension formatting,
not for fallback by \number_format() and \localeconv() .
|
|
protected
int[]
|
$localeCategories
System setlocale() category to set up system locale automatically in parent::SetView() method.
This property is used only for fallback if formatting is not by Intl extension.
System setlocale() category to set up system locale automatically in parent::SetView() method.
This property is used only for fallback if formatting is not by Intl extension.
|
#
[LC_NUMERIC, LC_MONETARY]
|