Namespace: MvcCore\Ext\Views\Helpers
See:
http://php.net/manual/en/numberformatter.create.php
See:
http://php.net/manual/en/numberformatter.format.php
See:
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle
See:
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details
See:
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details
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/numberformatter.settextattribute.php
See:
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute
See:
http://php.net/manual/en/function.number-format.php
See:
http://php.net/manual/en/function.localeconv.php
Located at ext-view-helper-formatnumber/src/MvcCore/Ext/Views/Helpers/FormatNumberHelper.php
Methods summary
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetDefaultDecimalsCount( integer $defaultDecimalsCount = 2 )
Set default numerics count after decimal point.
Set default numerics count after decimal point.
Parameters
Returns
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetIntlDefaultStyle( integer $intlDefaultStyle = 1 )
Set default style of the formatting, one of the format style constants if second link.
If \NumberFormatter::PATTERN_DECIMAL or \NumberFormatter::PATTERN_RULEBASED
is passed then the number format is opened using the given pattern, which must
conform to the syntax described in » ICU DecimalFormat documentation or
» ICU RuleBasedNumberFormat documentation, respectively.
This setter is used for Intl number formatter.
Set default style of the formatting, one of the format style constants if second link.
If \NumberFormatter::PATTERN_DECIMAL or \NumberFormatter::PATTERN_RULEBASED
is passed then the number format is opened using the given pattern, which must
conform to the syntax described in » ICU DecimalFormat documentation or
» ICU RuleBasedNumberFormat documentation, respectively.
This setter is used for Intl number formatter.
Parameters
Returns
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetIntlDefaultPattern( string $intlDefaultPattern = '' )
Set default pattern string if the chosen style requires a pattern.
This setter is used for Intl number formatter.
Set default pattern string if the chosen style requires a pattern.
This setter is used for Intl number formatter.
Parameters
Returns
See
http://php.net/manual/en/numberformatter.create.php
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetIntlDefaultAttributes( array $intlDefaultAttributes = [] )
Set default set of numeric attribute(s) associated with Intl number formatter.
Array with keys describing number formatter constants and with values describing specific values.
Set default set of numeric attribute(s) associated with Intl number formatter.
Array with keys describing number formatter constants and with values describing specific values.
Parameters
Returns
See
http://php.net/manual/en/numberformatter.setattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetIntlDefaultTextAttributes( array $intlDefaultTextAttributes = [] )
Set default set of text attribute(s) associated with Intl number formatter.
Array with keys describing number formatter constants and with values describing specific values.
Set default set of text attribute(s) associated with Intl number formatter.
Array with keys describing number formatter constants and with values describing specific values.
Parameters
- $intlDefaultTextAttributes
Returns
See
http://php.net/manual/en/numberformatter.settextattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetLocaleConventions( array $localeConventions = [] )
Set custom number (and money) formatting conventions if you don't want to use
automatically assigned formatting conventions by system locale settings.
You have to define all keys defined in property $this->defaultLocaleConventions; .
Use this function only for fallback if formatting is not by Intl extension.
Set custom number (and money) formatting conventions if you don't want to use
automatically assigned formatting conventions by system locale settings.
You have to define all keys defined in property $this->defaultLocaleConventions; .
Use this function only for fallback if formatting is not by Intl extension.
Parameters
- $localeConventions
- Locale specific number formatting conventions.
Returns
See
http://php.net/manual/en/function.localeconv.php
|
public
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
#
SetDefaultLocaleConventions( string[] $defaultLocaleConventions = [] )
Set default locale conventions used for Intl formatting fallback,
when is not possible to configure system locale value
and when there is necessary to define some default formatting rules.
Set default locale conventions used for Intl formatting fallback,
when is not possible to configure system locale value
and when there is necessary to define some default formatting rules.
Parameters
- $defaultLocaleConventions
Returns
See
http://php.net/manual/en/function.localeconv.php
|
public
string
|
#
FormatNumber( integer|float|string $number = NULL, integer|null $decimalsCount = NULL, string|null $formatterStyleOrDecimalPoint = NULL , array|string|null $formatterPatternOrThousandsSeparator = NULL, array|null $formatterAttributes = NULL, array|null $formatterTextAttributes = NULL )
Format number (first argument) by explicitly given next following arguments
or by default settings configured by it's setters. This function uses two
ways to format numbers:
Format number (first argument) by explicitly given next following arguments
or by default settings configured by it's setters. This function uses two
ways to format numbers:
1) Formatting by Intl extension - creating \NumberFormatter instance and calling format() function. You can format first argument by explicitly given next following arguments to create formatter instance. If there are no next following arguments, there are used default arguments to create formatter instance defined by it's helper setters above.
2) Formatting fallback by number_format() with explicitly given next following arguments to specify decimals count, decimal point and thousands separator. If there are no values for decimal point and thousands separator, there is used values from protected $this->localeConventions array, which should be defined by it's setter method. And if this array is not defined, there is used format conventions by system locale settings by request object language and locale. This method is used as fallback for Intl extension.
Parameters
- $number
- The number being formatted.
- $decimalsCount
Optional, numerics count after decimal point. If NULL ,
there is used configurable property $this->defaultDecimalsCount .
- $formatterStyleOrDecimalPoint
1) Optional, \NumberFormatter constant to choose proper localized
formatter (\NumberFormatter::DECIMAL , \NumberFormatter::PERCENT ,
\NumberFormatter::SPELLOUT , \NumberFormatter::DURATION ...).
2) Optional, decimal point separator for number_format() fallback.
If NULL , there is used system locale settings value and if
there are no locale system settings, there is used dot char - . .
- $formatterPatternOrThousandsSeparator
1) Optional, number formatter pattern for following style constants:
- \NumberFormatter::PATTERN_DECIMAL
- \NumberFormatter::PATTERN_RULEBASED
2) Optional, thousands separator for number_format() fallback.
If NULL , there is used system locale settings value and if there
is no system locale settings, there is used comma char - , .
- $formatterAttributes
1) Optional number formatter attributes, for example to max./min.
integer digits etc...
- $formatterTextAttributes
- 1) Optional number formatter text attributes.
Returns
string
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/numberformatter.format.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details
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/numberformatter.settextattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute
http://php.net/manual/en/function.number-format.php
http://php.net/manual/en/function.localeconv.php
|
protected
string
|
#
formatByIntlNumberFormatter( integer|float $valueToFormat = 0.0, integer|null $decimalsCount = NULL, integer|null $style = NULL, string|null $pattern = NULL , array|null $attributes = NULL, array|null $textAttributes = NULL )
Format number by numfmt_format() (PHP Intl extension) with explicitly given
$style , $pattern , $attributes or $textAttributes . If there are no explicitly given
arguments, there are used default values configured by it's setter methods above.
Format number by numfmt_format() (PHP Intl extension) with explicitly given
$style , $pattern , $attributes or $textAttributes . If there are no explicitly given
arguments, there are used default values configured by it's setter methods above.
Parameters
- $valueToFormat
- Numeric value to format.
- $decimalsCount
Optional, numerics count after decimal point. If NULL ,
there is used configurable property $this->defaultDecimalsCount .
- $style
\NumberFormatter constant to choose proper localized formatter.
- $pattern
Optional pattern for style constants
NumberFormatter::PATTERN_DECIMAL or
\NumberFormatter::PATTERN_RULEBASED .
- $attributes
- Optional formatter attributes.
- $textAttributes
- Optional formatter text attributes.
Returns
string
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/numberformatter.format.php
|
protected
NumberFormatter
|
#
getIntlNumberFormatter( string|null $langAndLocale = NULL, integer|null $style = NULL, integer|null $pattern = NULL, array $attributes = [], array $textAttributes = [] )
Get stored \NumberFormatter instance or create new one.
Get stored \NumberFormatter instance or create new one.
Parameters
- $langAndLocale
- $style
- $pattern
- $attributes
- $textAttributes
Returns
NumberFormatter
|
protected
string
|
#
fallbackFormatByNumberFormat( integer|float $valueToFormat = 0.0, integer|null $decimalsCount = NULL, string|null $decimalPoint = NULL, string|null $thousandsSeparator = NULL )
Format a number with PHP number_format() with optionally given decimals count,
by optionally given decimal point and by optionally given thousands separator.
If there are no values for decimal point and thousands separator, there is
used values from protected $this->localeConventions array, which should be defined
by it's setter method. And if this array is not defined, there is used
format conventions by system locale settings by request object language and locale.
This method is used as fallback for Intl extension.
Format a number with PHP number_format() with optionally given decimals count,
by optionally given decimal point and by optionally given thousands separator.
If there are no values for decimal point and thousands separator, there is
used values from protected $this->localeConventions array, which should be defined
by it's setter method. And if this array is not defined, there is used
format conventions by system locale settings by request object language and locale.
This method is used as fallback for Intl extension.
Parameters
- $valueToFormat
- The number being formatted.
- $decimalsCount
Optional, numerics count after decimal point,
If NULL , there is used configurable property
$this->defaultDecimalsCount .
- $decimalPoint
Optional, separator for the decimal point.
If NULL , there is used system locale settings.
- $thousandsSeparator
Optional, thousands separator. If NULL ,
there is used system locale settings.
Returns
string
See
http://php.net/manual/en/function.number-format.php
http://php.net/manual/en/function.localeconv.php
|
protected
|
#
setUpLocaleConventions( )
Try to set up local conventions by system locale settings
only if there was any success with setting up system locale.
If system locale is not set up properly - use default formatting conventions.
Try to set up local conventions by system locale settings
only if there was any success with setting up system locale.
If system locale is not set up properly - use default formatting conventions.
See
http://php.net/manual/en/function.localeconv.php
|
Properties summary
protected static
MvcCore\Ext\Views\Helpers\FormatNumberHelper
|
$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\FormatNumber::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\FormatNumber::GetInstance()
|
|
protected
integer|null
|
$defaultDecimalsCount
Default numerics count after decimal point.
Default numerics count after decimal point.
|
|
protected
integer
|
$intlDefaultStyle
Default style of the formatting, one of the format style constants in second link.
If \NumberFormatter::PATTERN_DECIMAL or \NumberFormatter::PATTERN_RULEBASED
is passed then the number format is opened using the given pattern, which must
conform to the syntax described in » ICU DecimalFormat documentation or
» ICU RuleBasedNumberFormat documentation, respectively.
Default style of the formatting, one of the format style constants in second link.
If \NumberFormatter::PATTERN_DECIMAL or \NumberFormatter::PATTERN_RULEBASED
is passed then the number format is opened using the given pattern, which must
conform to the syntax described in » ICU DecimalFormat documentation or
» ICU RuleBasedNumberFormat documentation, respectively.
See
http://php.net/manual/en/numberformatter.create.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle
http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details
http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details
|
|
protected
string|null
|
$intlDefaultPattern
Default pattern string if the chosen style requires a pattern.
Default pattern string if the chosen style requires a pattern.
See
http://php.net/manual/en/numberformatter.create.php
|
|
protected
int[]
|
$intlDefaultAttributes
Default set of numeric attribute(s) associated with the formatter.
Array with keys describing number formatter constants and with values describing specific values.
Default set of numeric attribute(s) associated with the formatter.
Array with keys describing number formatter constants and with values describing specific values.
See
http://php.net/manual/en/numberformatter.setattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute
|
|
protected
int[]
|
$intlDefaultTextAttributes
Default set of text attribute(s) associated with the formatter.
Array with keys describing number formatter constants and with values describing specific values.
Default set of text attribute(s) associated with the formatter.
Array with keys describing number formatter constants and with values describing specific values.
See
http://php.net/manual/en/numberformatter.settextattribute.php
http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute
|
|
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.
|
|
protected
stdClass|null
|
$localeConventions
Numeric formatting information by system locale settings.
There are used all keys defined in property $this->defaultLocaleConventions; .
This property is used only for fallback if formatting is not by Intl extension.
Numeric formatting information by system locale settings.
There are used all keys defined in property $this->defaultLocaleConventions; .
This property is used only for fallback if formatting is not by Intl extension.
See
http://php.net/manual/en/function.localeconv.php
|
|
protected
array|stdClass
|
$defaultLocaleConventions
Default locale conventions used for Intl formatting fallback,
when is not possible to configure system locale value
and when there is necessary to define some default formatting rules.
Default locale conventions used for Intl formatting fallback,
when is not possible to configure system locale value
and when there is necessary to define some default formatting rules.
See
http://php.net/manual/en/function.localeconv.php
|
#
[
'decimal_point' => '.',
'thousands_sep' => ',',
'mon_decimal_point' => '.',
'mon_thousands_sep' => ',',
'int_curr_symbol' => 'USD',
'currency_symbol' => '$',
'frac_digits' => 2,
'positive_sign' => '',
'negative_sign' => '-',
'p_cs_precedes' => 1,
'n_cs_precedes' => 1,
'p_sep_by_space' => 0,
'n_sep_by_space' => 0,
'p_sign_posn' => 3,
'n_sign_posn' => 3,
]
|