PHP Класс yii\i18n\Formatter

The formatting methods provided by Formatter are all named in the form of asXyz(). The behavior of some of them may be configured via the properties of Formatter. For example, by configuring [[dateFormat]], one may control how Formatter::asDate formats the value into a date string. Formatter is configured as an application component in Application by default. You can access that instance via Yii::$app->formatter. The Formatter class is designed to format values according to a [[locale]]. For this feature to work the PHP intl extension has to be installed. Most of the methods however work also if the PHP intl extension is not installed by providing a fallback implementation. Without intl month and day names are in English only.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Автор: Enrica Ruedin ([email protected])
Автор: Carsten Brandt ([email protected])
Наследование: extends yii\base\Component
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$booleanFormat the text to be displayed when formatting a boolean value. The first element corresponds to the text displayed for false, the second element for true. Defaults to ['No', 'Yes'], where Yes and No will be translated according to [[locale]].
$calendar the calendar to be used for date formatting. The value of this property will be directly passed to the constructor of the IntlDateFormatter class. Defaults to null, which means the Gregorian calendar will be used. You may also explicitly pass the constant \IntlDateFormatter::GREGORIAN for Gregorian calendar. To use an alternative calendar like for example the Jalali calendar, set this property to \IntlDateFormatter::TRADITIONAL. The calendar must then be specified in the [[locale]], for example for the persian calendar the configuration for the formatter would be: php 'formatter' => [ 'locale' => 'fa_IR@calendar=persian', 'calendar' => \IntlDateFormatter::TRADITIONAL, ], Available calendar names can be found in the ICU manual. Since PHP 5.5 you may also use an instance of the [[\IntlCalendar]] class. Check the PHP manual for more details. If the PHP intl extension is not available, setting this property will have no effect.
$currencyCode the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]]. If not set, the currency code corresponding to [[locale]] will be used. Note that in this case the [[locale]] has to be specified with a country code, e.g. en-US otherwise it is not possible to determine the default currency.
$dateFormat the default format string to be used to format a [[asDate()|date]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy' // date in ICU format 'php:m/d/Y' // the same date in PHP format
$datetimeFormat the default format string to be used to format a [[asDatetime()|date and time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy HH:mm:ss' // date and time in ICU format 'php:m/d/Y H:i:s' // the same date and time in PHP format
$decimalSeparator the character displayed as the decimal point when formatting a number. If not set, the decimal separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is '.'.
$defaultTimeZone the time zone that is assumed for input values if they do not include a time zone explicitly. The value must be a valid time zone identifier, e.g. UTC, Europe/Berlin or America/Chicago. Please refer to the php manual for available time zones. It defaults to UTC so you only have to adjust this value if you store datetime values in another time zone in your database.
$locale the locale ID that is used to localize the date and number formatting. For number and date formatting this is only effective when the PHP intl extension is installed. If not set, [[\yii\base\Application::language]] will be used.
$nullDisplay the text to be displayed when formatting a null value. Defaults to '(not set)', where (not set) will be translated according to [[locale]].
$numberFormatterOptions a list of name value pairs that are passed to the intl Numberformatter::setAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following: php [ NumberFormatter::MIN_FRACTION_DIGITS => 0, NumberFormatter::MAX_FRACTION_DIGITS => 2, ]
$numberFormatterSymbols a list of name value pairs that are passed to the intl Numberformatter::setSymbol() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to choose a custom currency symbol, e.g. U+20BD instead of руб. for Russian Ruble: php [ NumberFormatter::CURRENCY_SYMBOL => '₽', ]
$numberFormatterTextOptions a list of name value pairs that are passed to the intl Numberformatter::setTextAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to change the minus sign for negative numbers you can configure this property like the following: php [ NumberFormatter::NEGATIVE_PREFIX => 'MINUS', ]
$sizeFormatBase the base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [[asSize]] and [[asShortSize]]. Defaults to 1024.
$thousandSeparator the character displayed as the thousands separator (also called grouping separator) character when formatting a number. If not set, the thousand separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is ','.
$timeFormat the default format string to be used to format a [[asTime()|time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'HH:mm:ss' // time in ICU format 'php:H:i:s' // the same time in PHP format
$timeZone the time zone to use for formatting time and date values. This can be any value that may be passed to date_default_timezone_set() e.g. UTC, Europe/Berlin or America/Chicago. Refer to the php manual for available time zones. If this property is not set, [[\yii\base\Application::timeZone]] will be used. Note that the default time zone for input data is assumed to be UTC by default if no time zone is included in the input date value. If you store your data in a different time zone in the database, you have to adjust [[defaultTimeZone]] accordingly.

Открытые методы

Метод Описание
asBoolean ( mixed $value ) : string Formats the value as a boolean.
asCurrency ( mixed $value, string $currency = null, array $options = [], array $textOptions = [] ) : string Formats the value as a currency number.
asDate ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a date.
asDatetime ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a datetime.
asDecimal ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a decimal number.
asDuration ( DateInterva\DateInterval | string | integer $value, string $implodeString = ', ', string $negativeSign = '-' ) : string Represents the value as duration in human readable format.
asEmail ( string $value, array $options = [] ) : string Formats the value as a mailto link.
asHtml ( string $value, array | null $config = null ) : string Formats the value as HTML text.
asImage ( mixed $value, array $options = [] ) : string Formats the value as an image tag.
asInteger ( mixed $value, array $options = [], array $textOptions = [] ) : string Formats the value as an integer number by removing any decimal digits without rounding.
asNtext ( string $value ) : string Formats the value as an HTML-encoded plain text with newlines converted into breaks.
asOrdinal ( mixed $value ) : string Formats the value as a ordinal value of a number.
asParagraphs ( string $value ) : string Formats the value as HTML-encoded text paragraphs.
asPercent ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a percent number with "%" sign.
asRaw ( mixed $value ) : string Formats the value as is without any formatting.
asRelativeTime ( integer | string | DateTim\DateTime | DateInterva\DateInterval $value, integer | string | DateTim\DateTime $referenceTime = null ) : string Formats the value as the time interval between a date and now in human readable form.
asScientific ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value as a scientific number.
asShortSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value in bytes as a size in human readable form for example 12 KB.
asSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string Formats the value in bytes as a size in human readable form, for example 12 kilobytes.
asSpellout ( mixed $value ) : string Formats the value as a number spellout.
asText ( string $value ) : string Formats the value as an HTML-encoded plain text.
asTime ( integer | string | DateTim\DateTime $value, string $format = null ) : string Formats the value as a time.
asTimestamp ( integer | string | DateTim\DateTime $value ) : string Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).
asUrl ( mixed $value, array $options = [] ) : string Formats the value as a hyperlink.
format ( mixed $value, string | array $format ) : string Formats the value based on the given format type.
init ( )

Защищенные методы

Метод Описание
createNumberFormatter ( integer $style, integer $decimals = null, array $options = [], array $textOptions = [] ) : NumberFormatter Creates a number formatter based on the given type and format.
normalizeDatetimeValue ( integer | string | DateTim\DateTime $value, boolean $checkTimeInfo = false ) : DateTim\DateTime | array Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods.
normalizeNumericValue ( mixed $value ) : float | integer Normalizes a numeric input value

Приватные методы

Метод Описание
formatDateTimeValue ( integer | string | DateTim\DateTime $value, string $format, string $type ) : string
formatSizeNumber ( string | integer | float $value, integer $decimals, array $options, array $textOptions ) : array Given the value in bytes formats number part of the human readable form.

Описание методов

asBoolean() публичный Метод

Formats the value as a boolean.
См. также: booleanFormat
public asBoolean ( mixed $value ) : string
$value mixed the value to be formatted.
Результат string the formatted result.

asCurrency() публичный Метод

This function does not require the PHP intl extension to be installed to work, but it is highly recommended to install it to get good formatting results.
public asCurrency ( mixed $value, string $currency = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$currency string the 3-letter ISO 4217 currency code indicating the currency to use. If null, [[currencyCode]] will be used.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asDate() публичный Метод

Formats the value as a date.
См. также: dateFormat
public asDate ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[dateFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
Результат string the formatted result.

asDatetime() публичный Метод

Formats the value as a datetime.
См. также: datetimeFormat
public asDatetime ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[dateFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
Результат string the formatted result.

asDecimal() публичный Метод

Property [[decimalSeparator]] will be used to represent the decimal point. The value is rounded automatically to the defined decimal digits.
См. также: decimalSeparator
См. также: thousandSeparator
public asDecimal ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$decimals integer the number of digits after the decimal point. If not given the number of digits is determined from the [[locale]] and if the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available defaults to `2`.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asDuration() публичный Метод

Represents the value as duration in human readable format.
С версии: 2.0.7
public asDuration ( DateInterva\DateInterval | string | integer $value, string $implodeString = ', ', string $negativeSign = '-' ) : string
$value DateInterva\DateInterval | string | integer the value to be formatted. Acceptable formats: - [DateInterval object](http://php.net/manual/ru/class.dateinterval.php) - integer - number of seconds. For example: value `131` represents `2 minutes, 11 seconds` - ISO8601 duration format. For example, all of these values represent `1 day, 2 hours, 30 minutes` duration: `2015-01-01T13:00:00Z/2015-01-02T13:30:00Z` - between two datetime values `2015-01-01T13:00:00Z/P1D2H30M` - time interval after datetime value `P1D2H30M/2015-01-02T13:30:00Z` - time interval before datetime value `P1D2H30M` - simply a date interval `P-1D2H30M` - a negative date interval (`-1 day, 2 hours, 30 minutes`)
$implodeString string will be used to concatenate duration parts. Defaults to `, `.
$negativeSign string will be prefixed to the formatted duration, when it is negative. Defaults to `-`.
Результат string the formatted duration.

asEmail() публичный Метод

Formats the value as a mailto link.
public asEmail ( string $value, array $options = [] ) : string
$value string the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::mailto()]].
Результат string the formatted result.

asHtml() публичный Метод

The value will be purified using [[HtmlPurifier]] to avoid XSS attacks. Use Formatter::asRaw if you do not want any purification of the value.
public asHtml ( string $value, array | null $config = null ) : string
$value string the value to be formatted.
$config array | null the configuration for the HTMLPurifier class.
Результат string the formatted result.

asImage() публичный Метод

Formats the value as an image tag.
public asImage ( mixed $value, array $options = [] ) : string
$value mixed the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::img()]].
Результат string the formatted result.

asInteger() публичный Метод

Formats the value as an integer number by removing any decimal digits without rounding.
public asInteger ( mixed $value, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asNtext() публичный Метод

Formats the value as an HTML-encoded plain text with newlines converted into breaks.
public asNtext ( string $value ) : string
$value string the value to be formatted.
Результат string the formatted result.

asOrdinal() публичный Метод

This function requires the PHP intl extension to be installed.
public asOrdinal ( mixed $value ) : string
$value mixed the value to be formatted
Результат string the formatted result.

asParagraphs() публичный Метод

Each text paragraph is enclosed within a

tag. One or multiple consecutive empty lines divide two paragraphs.

public asParagraphs ( string $value ) : string
$value string the value to be formatted.
Результат string the formatted result.

asPercent() публичный Метод

Formats the value as a percent number with "%" sign.
public asPercent ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted. It must be a factor e.g. `0.75` will result in `75%`.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asRaw() публичный Метод

This method simply returns back the parameter without any format. The only exception is a null value which will be formatted using [[nullDisplay]].
public asRaw ( mixed $value ) : string
$value mixed the value to be formatted.
Результат string the formatted result.

asRelativeTime() публичный Метод

This method can be used in three different ways: 1. Using a timestamp that is relative to now. 2. Using a timestamp that is relative to the $referenceTime. 3. Using a DateInterval object.
public asRelativeTime ( integer | string | DateTim\DateTime | DateInterva\DateInterval $value, integer | string | DateTim\DateTime $referenceTime = null ) : string
$value integer | string | DateTim\DateTime | DateInterva\DateInterval the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object - a PHP DateInterval object (a positive time interval will refer to the past, a negative one to the future)
$referenceTime integer | string | DateTim\DateTime if specified the value is used as a reference time instead of `now` when `$value` is not a `DateInterval` object.
Результат string the formatted result.

asScientific() публичный Метод

Formats the value as a scientific number.
public asScientific ( mixed $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value mixed the value to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asShortSize() публичный Метод

This is the short form of [[asSize]]. If [[sizeFormatBase]] is 1024, binary prefixes (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
См. также: sizeFormatBase
См. также: asSize
public asShortSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value string | integer | float value in bytes to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asSize() публичный Метод

If [[sizeFormatBase]] is 1024, binary prefixes (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
См. также: sizeFormatBase
См. также: asShortSize
public asSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value string | integer | float value in bytes to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат string the formatted result.

asSpellout() публичный Метод

This function requires the PHP intl extension to be installed.
public asSpellout ( mixed $value ) : string
$value mixed the value to be formatted
Результат string the formatted result.

asText() публичный Метод

Formats the value as an HTML-encoded plain text.
public asText ( string $value ) : string
$value string the value to be formatted.
Результат string the formatted result.

asTime() публичный Метод

Formats the value as a time.
См. также: timeFormat
public asTime ( integer | string | DateTim\DateTime $value, string $format = null ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$format string the format used to convert the value into a date string. If null, [[timeFormat]] will be used. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](http://php.net/manual/en/function.date.php)-function.
Результат string the formatted result.

asTimestamp() публичный Метод

Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).
public asTimestamp ( integer | string | DateTim\DateTime $value ) : string
$value integer | string | DateTim\DateTime the value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
Результат string the formatted result.

asUrl() публичный Метод

Formats the value as a hyperlink.
public asUrl ( mixed $value, array $options = [] ) : string
$value mixed the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::a()]].
Результат string the formatted result.

createNumberFormatter() защищенный Метод

You may override this method to create a number formatter based on patterns.
protected createNumberFormatter ( integer $style, integer $decimals = null, array $options = [], array $textOptions = [] ) : NumberFormatter
$style integer the type of the number formatter. Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, ::SPELLOUT, ::ORDINAL ::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
Результат NumberFormatter the created formatter instance

format() публичный Метод

This method will call one of the "as" methods available in this class to do the formatting. For type "xyz", the method "asXyz" will be used. For example, if the format is "html", then Formatter::asHtml will be used. Format names are case insensitive.
public format ( mixed $value, string | array $format ) : string
$value mixed the value to be formatted.
$format string | array the format of the value, e.g., "html", "text". To specify additional parameters of the formatting method, you may use an array. The first element of the array specifies the format name, while the rest of the elements will be used as the parameters to the formatting method. For example, a format of `['date', 'Y-m-d']` will cause the invocation of `asDate($value, 'Y-m-d')`.
Результат string the formatting result.

init() публичный Метод

public init ( )

normalizeDatetimeValue() защищенный Метод

Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods.
protected normalizeDatetimeValue ( integer | string | DateTim\DateTime $value, boolean $checkTimeInfo = false ) : DateTim\DateTime | array
$value integer | string | DateTim\DateTime the datetime value to be normalized. The following types of value are supported: - an integer representing a UNIX timestamp - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [[defaultTimeZone]] unless a time zone is explicitly given. - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
$checkTimeInfo boolean whether to also check if the date/time value has some time information attached. Defaults to `false`. If `true`, the method will then return an array with the first element being the normalized timestamp and the second a boolean indicating whether the timestamp has time information or it is just a date value. This parameter is available since version 2.0.1.
Результат DateTim\DateTime | array the normalized datetime value. Since version 2.0.1 this may also return an array if `$checkTimeInfo` is true. The first element of the array is the normalized timestamp and the second is a boolean indicating whether the timestamp has time information or it is just a date value.

normalizeNumericValue() защищенный Метод

- everything empty will result in 0 - a numeric string will be casted to float - everything else will be returned if it is numeric, otherwise an exception is thrown.
protected normalizeNumericValue ( mixed $value ) : float | integer
$value mixed the input value
Результат float | integer the normalized number value

Описание свойств

$booleanFormat публичное свойство

the text to be displayed when formatting a boolean value. The first element corresponds to the text displayed for false, the second element for true. Defaults to ['No', 'Yes'], where Yes and No will be translated according to [[locale]].
public $booleanFormat

$calendar публичное свойство

the calendar to be used for date formatting. The value of this property will be directly passed to the constructor of the IntlDateFormatter class. Defaults to null, which means the Gregorian calendar will be used. You may also explicitly pass the constant \IntlDateFormatter::GREGORIAN for Gregorian calendar. To use an alternative calendar like for example the Jalali calendar, set this property to \IntlDateFormatter::TRADITIONAL. The calendar must then be specified in the [[locale]], for example for the persian calendar the configuration for the formatter would be: php 'formatter' => [ 'locale' => 'fa_IR@calendar=persian', 'calendar' => \IntlDateFormatter::TRADITIONAL, ], Available calendar names can be found in the ICU manual. Since PHP 5.5 you may also use an instance of the [[\IntlCalendar]] class. Check the PHP manual for more details. If the PHP intl extension is not available, setting this property will have no effect.
См. также: http://php.net/manual/en/intldateformatter.create.php
См. также: http://php.net/manual/en/class.intldateformatter.php#intl.intldateformatter-constants.calendartypes
См. также: http://php.net/manual/en/class.intlcalendar.php
С версии: 2.0.7
public $calendar

$currencyCode публичное свойство

the 3-letter ISO 4217 currency code indicating the default currency to use for [[asCurrency]]. If not set, the currency code corresponding to [[locale]] will be used. Note that in this case the [[locale]] has to be specified with a country code, e.g. en-US otherwise it is not possible to determine the default currency.
public $currencyCode

$dateFormat публичное свойство

the default format string to be used to format a [[asDate()|date]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy' // date in ICU format 'php:m/d/Y' // the same date in PHP format
public $dateFormat

$datetimeFormat публичное свойство

the default format string to be used to format a [[asDatetime()|date and time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'MM/dd/yyyy HH:mm:ss' // date and time in ICU format 'php:m/d/Y H:i:s' // the same date and time in PHP format
public $datetimeFormat

$decimalSeparator публичное свойство

the character displayed as the decimal point when formatting a number. If not set, the decimal separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is '.'.
public $decimalSeparator

$defaultTimeZone публичное свойство

the time zone that is assumed for input values if they do not include a time zone explicitly. The value must be a valid time zone identifier, e.g. UTC, Europe/Berlin or America/Chicago. Please refer to the php manual for available time zones. It defaults to UTC so you only have to adjust this value if you store datetime values in another time zone in your database.
С версии: 2.0.1
public $defaultTimeZone

$locale публичное свойство

the locale ID that is used to localize the date and number formatting. For number and date formatting this is only effective when the PHP intl extension is installed. If not set, [[\yii\base\Application::language]] will be used.
public $locale

$nullDisplay публичное свойство

the text to be displayed when formatting a null value. Defaults to '(not set)', where (not set) will be translated according to [[locale]].
public $nullDisplay

$numberFormatterOptions публичное свойство

a list of name value pairs that are passed to the intl Numberformatter::setAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following: php [ NumberFormatter::MIN_FRACTION_DIGITS => 0, NumberFormatter::MAX_FRACTION_DIGITS => 2, ]
public $numberFormatterOptions

$numberFormatterSymbols публичное свойство

a list of name value pairs that are passed to the intl Numberformatter::setSymbol() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to choose a custom currency symbol, e.g. U+20BD instead of руб. for Russian Ruble: php [ NumberFormatter::CURRENCY_SYMBOL => '₽', ]
С версии: 2.0.4
public $numberFormatterSymbols

$numberFormatterTextOptions публичное свойство

a list of name value pairs that are passed to the intl Numberformatter::setTextAttribute() method of all the number formatter objects created by Formatter::createNumberFormatter. This property takes only effect if the PHP intl extension is installed. Please refer to the PHP manual for the possible options. For example to change the minus sign for negative numbers you can configure this property like the following: php [ NumberFormatter::NEGATIVE_PREFIX => 'MINUS', ]
public $numberFormatterTextOptions

$sizeFormatBase публичное свойство

the base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [[asSize]] and [[asShortSize]]. Defaults to 1024.
public $sizeFormatBase

$thousandSeparator публичное свойство

the character displayed as the thousands separator (also called grouping separator) character when formatting a number. If not set, the thousand separator corresponding to [[locale]] will be used. If PHP intl extension is not available, the default value is ','.
public $thousandSeparator

$timeFormat публичное свойство

the default format string to be used to format a [[asTime()|time]]. This can be "short", "medium", "long", or "full", which represents a preset format of different lengths. It can also be a custom format as specified in the ICU manual. Alternatively this can be a string prefixed with php: representing a format that can be recognized by the PHP date()-function. For example: php 'HH:mm:ss' // time in ICU format 'php:H:i:s' // the same time in PHP format
public $timeFormat

$timeZone публичное свойство

the time zone to use for formatting time and date values. This can be any value that may be passed to date_default_timezone_set() e.g. UTC, Europe/Berlin or America/Chicago. Refer to the php manual for available time zones. If this property is not set, [[\yii\base\Application::timeZone]] will be used. Note that the default time zone for input data is assumed to be UTC by default if no time zone is included in the input date value. If you store your data in a different time zone in the database, you have to adjust [[defaultTimeZone]] accordingly.
public $timeZone