# Formatter

> Formatter provides a set of commonly used data formatting methods.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [i18n](/docs/api/yii/i18n/index.md) › Formatter

| class | `yii\i18n\Formatter` |
| --- | --- |
| Extends | [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/i18n/Formatter.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/i18n/Formatter.php#L55) |

Formatter provides a set of commonly used data formatting methods.

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`](/docs/api/yii/i18n/formatter/index.md#property-dateFormat), one may control how [`asDate()`](/docs/api/yii/i18n/formatter/index.md#method-asDate) formats the value into a date string.

Formatter is configured as an application component in [`Application`](/docs/api/yii/base/application/index.md) by default.
You can access that instance via `Yii::$app->formatter`.

The Formatter class is designed to format values according to a [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale). For this feature to work
the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) 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.
Note that even if the intl extension is installed, formatting date and time values for years >=2038 or &lt;=1901
on 32bit systems will fall back to the PHP implementation because intl uses a 32bit UNIX timestamp internally.
On a 64bit system the intl formatter is used in all cases if installed.

> Note: The Formatter class is meant to be used for formatting values for display to users in different
> languages and time zones. If you need to format a date or time in machine readable format, use the
> PHP [date()](https://www.php.net/manual/en/function.date.php) function instead.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-baseUnits"></span>`$baseUnits` | `array` | The base units that are used as multipliers for smallest possible unit from [`$measureUnits`](/docs/api/yii/i18n/formatter/index.md#property-measureUnits). Default: `[self::UNIT_LENGTH => [self::UNIT_SYSTEM_IMPERIAL => 12, self::UNIT_SYSTEM_METRIC => 1000], self::UNIT_WEIGHT => [self::UNIT_SYSTEM_IMPERIAL => 7000, self::UNIT_SYSTEM_METRIC => 1000]]`. Available since 2.0.13. | `Formatter` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`$booleanFormat`](#property-booleanFormat) | `array` | The text to be displayed when formatting a boolean value. Default: `null`. | `Formatter` |
| [`$calendar`](#property-calendar) | [`IntlCalendar`](https://www.php.net/manual/en/class.intlcalendar.php)`\|int\|null` | The calendar to be used for date formatting. Default: `null`. Available since 2.0.7. | `Formatter` |
| [`$currencyCode`](#property-currencyCode) | `string\|null` | The 3-letter ISO 4217 currency code indicating the default currency to use for [`asCurrency()`](/docs/api/yii/i18n/formatter/index.md#method-asCurrency). Default: `null`. | `Formatter` |
| [`$currencyDecimalSeparator`](#property-currencyDecimalSeparator) | `string\|null` | The character displayed as the decimal point when formatting a currency. Default: `null`. Available since 2.0.35. | `Formatter` |
| [`$dateFormat`](#property-dateFormat) | `string` | The default format string to be used to format a [date](/docs/api/yii/i18n/formatter/index.md#method-asDate). Default: `'medium'`. | `Formatter` |
| [`$datetimeFormat`](#property-datetimeFormat) | `string` | The default format string to be used to format a [date and time](/docs/api/yii/i18n/formatter/index.md#method-asDatetime). Default: `'medium'`. | `Formatter` |
| [`$decimalSeparator`](#property-decimalSeparator) | `string\|null` | The character displayed as the decimal point when formatting a number. Default: `null`. | `Formatter` |
| [`$defaultTimeZone`](#property-defaultTimeZone) | `string` | The time zone that is assumed for input values if they do not include a time zone explicitly. Default: `'UTC'`. Available since 2.0.1. | `Formatter` |
| [`$language`](#property-language) | `string\|null` | The language code (e.g. `en-US`, `en`) that is used to translate internal messages. Default: `null`. Available since 2.0.28. | `Formatter` |
| [`$locale`](#property-locale) | `string\|null` | The locale ID that is used to localize the date and number formatting. Default: `null`. | `Formatter` |
| [`$measureUnits`](#property-measureUnits) | `array` | Configuration of weight and length measurement units. Default: `[self::UNIT_LENGTH => [self::UNIT_SYSTEM_IMPERIAL => ['inch' => 1, 'foot' => 12, 'yard' => 36, 'chain' => 792, 'furlong' => 7920, 'mile' => 63360], self::UNIT_SYSTEM_METRIC => ['millimeter' => 1, 'centimeter' => 10, 'meter' => 1000, 'kilometer' => 1000000]], self::UNIT_WEIGHT => [self::UNIT_SYSTEM_IMPERIAL => ['grain' => 1, 'drachm' => 27.34375, 'ounce' => 437.5, 'pound' => 7000, 'stone' => 98000, 'quarter' => 196000, 'hundredweight' => 784000, 'ton' => 15680000], self::UNIT_SYSTEM_METRIC => ['gram' => 1, 'kilogram' => 1000, 'ton' => 1000000]]]`. Available since 2.0.13. | `Formatter` |
| [`$nullDisplay`](#property-nullDisplay) | `string\|null` | The text to be displayed when formatting a `null` value. Default: `null`. | `Formatter` |
| [`$numberFormatterOptions`](#property-numberFormatterOptions) | `array` | A list of name value pairs that are passed to the intl [NumberFormatter::setAttribute()](https://www.php.net/manual/en/numberformatter.setattribute.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter). Default: `[]`. | `Formatter` |
| [`$numberFormatterSymbols`](#property-numberFormatterSymbols) | `array` | A list of name value pairs that are passed to the intl [NumberFormatter::setSymbol()](https://www.php.net/manual/en/numberformatter.setsymbol.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter). Default: `[]`. Available since 2.0.4. | `Formatter` |
| [`$numberFormatterTextOptions`](#property-numberFormatterTextOptions) | `array` | A list of name value pairs that are passed to the intl [NumberFormatter::setTextAttribute()](https://www.php.net/manual/en/numberformatter.settextattribute.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter). Default: `[]`. | `Formatter` |
| [`$sizeFormatBase`](#property-sizeFormatBase) | `int` | The base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [`asSize()`](/docs/api/yii/i18n/formatter/index.md#method-asSize) and [`asShortSize()`](/docs/api/yii/i18n/formatter/index.md#method-asShortSize). Default: `1024`. | `Formatter` |
| [`$systemOfUnits`](#property-systemOfUnits) | `string` | Default system of measure units. Default: `self::UNIT_SYSTEM_METRIC`. Available since 2.0.13. | `Formatter` |
| [`$thousandSeparator`](#property-thousandSeparator) | `string\|null` | The character displayed as the thousands separator (also called grouping separator) character when formatting a number. Default: `null`. | `Formatter` |
| [`$timeFormat`](#property-timeFormat) | `string` | The default format string to be used to format a [time](/docs/api/yii/i18n/formatter/index.md#method-asTime). Default: `'medium'`. | `Formatter` |
| [`$timeZone`](#property-timeZone) | `string\|null` | The time zone to use for formatting time and date values. Default: `null`. | `Formatter` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`asBoolean()`](#method-asBoolean) | Formats the value as a boolean. | `Formatter` |
| [`asCurrency()`](#method-asCurrency) | Formats the value as a currency number. | `Formatter` |
| [`asDate()`](#method-asDate) | Formats the value as a date. | `Formatter` |
| [`asDatetime()`](#method-asDatetime) | Formats the value as a datetime. | `Formatter` |
| [`asDecimal()`](#method-asDecimal) | Formats the value as a decimal number. | `Formatter` |
| [`asDuration()`](#method-asDuration) | Represents the value as duration in human readable format. | `Formatter` |
| [`asEmail()`](#method-asEmail) | Formats the value as a mailto link. | `Formatter` |
| [`asHtml()`](#method-asHtml) | Formats the value as HTML text. | `Formatter` |
| [`asImage()`](#method-asImage) | Formats the value as an image tag. | `Formatter` |
| [`asInteger()`](#method-asInteger) | Formats the value as an integer number by removing any decimal digits without rounding. | `Formatter` |
| [`asLength()`](#method-asLength) | Formats the value as a length in human readable form for example `12 meters`. | `Formatter` |
| [`asNtext()`](#method-asNtext) | Formats the value as an HTML-encoded plain text with newlines converted into breaks. | `Formatter` |
| [`asOrdinal()`](#method-asOrdinal) | Formats the value as a ordinal value of a number. | `Formatter` |
| [`asParagraphs()`](#method-asParagraphs) | Formats the value as HTML-encoded text paragraphs. | `Formatter` |
| [`asPercent()`](#method-asPercent) | Formats the value as a percent number with "%" sign. | `Formatter` |
| [`asRaw()`](#method-asRaw) | Formats the value as is without any formatting. | `Formatter` |
| [`asRelativeTime()`](#method-asRelativeTime) | Formats the value as the time interval between a date and now in human readable form. | `Formatter` |
| [`asScientific()`](#method-asScientific) | Formats the value as a scientific number. | `Formatter` |
| [`asShortLength()`](#method-asShortLength) | Formats the value as a length in human readable form for example `12 m`. | `Formatter` |
| [`asShortSize()`](#method-asShortSize) | Formats the value in bytes as a size in human readable form for example `12 kB`. | `Formatter` |
| [`asShortWeight()`](#method-asShortWeight) | Formats the value as a weight in human readable form for example `12 kg`. | `Formatter` |
| [`asSize()`](#method-asSize) | Formats the value in bytes as a size in human readable form, for example `12 kilobytes`. | `Formatter` |
| [`asSpellout()`](#method-asSpellout) | Formats the value as a number spellout. | `Formatter` |
| [`asText()`](#method-asText) | Formats the value as an HTML-encoded plain text. | `Formatter` |
| [`asTime()`](#method-asTime) | Formats the value as a time. | `Formatter` |
| [`asTimestamp()`](#method-asTimestamp) | Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970). | `Formatter` |
| [`asUrl()`](#method-asUrl) | Formats the value as a hyperlink. | `Formatter` |
| [`asWeight()`](#method-asWeight) | Formats the value as a weight in human readable form for example `12 kilograms`. | `Formatter` |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`format()`](#method-format) | Formats the value based on the given format type. | `Formatter` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the object. | `Formatter` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`asCurrencyStringFallback()`](#method-asCurrencyStringFallback) protected | Fallback for formatting value as a currency number. | `Formatter` |
| [`asDecimalStringFallback()`](#method-asDecimalStringFallback) protected | Fallback for formatting value as a decimal number. | `Formatter` |
| [`asIntegerStringFallback()`](#method-asIntegerStringFallback) protected | Fallback for formatting value as an integer number by removing any decimal digits without rounding. | `Formatter` |
| [`asPercentStringFallback()`](#method-asPercentStringFallback) protected | Fallback for formatting value as a percent number with "%" sign. | `Formatter` |
| [`createNumberFormatter()`](#method-createNumberFormatter) protected | Creates a number formatter based on the given type and format. | `Formatter` |
| [`formatNumber()`](#method-formatNumber) protected | Given the value in bytes formats number part of the human readable form. | `Formatter` |
| [`isNormalizedValueMispresented()`](#method-isNormalizedValueMispresented) protected | Checks if string representations of given value and its normalized version are different. | `Formatter` |
| [`normalizeDatetimeValue()`](#method-normalizeDatetimeValue) protected | Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods. | `Formatter` |
| [`normalizeNumericStringValue()`](#method-normalizeNumericStringValue) protected | Normalizes a numeric string value. | `Formatter` |
| [`normalizeNumericValue()`](#method-normalizeNumericValue) protected | Normalizes a numeric input value. | `Formatter` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-UNIT_SYSTEM_METRIC"></span>`UNIT_SYSTEM_METRIC` | `'metric'` | Available since 2.0.13. | `Formatter` |
| <span id="const-UNIT_SYSTEM_IMPERIAL"></span>`UNIT_SYSTEM_IMPERIAL` | `'imperial'` | Available since 2.0.13. | `Formatter` |
| <span id="const-FORMAT_WIDTH_LONG"></span>`FORMAT_WIDTH_LONG` | `'long'` | Available since 2.0.13. | `Formatter` |
| <span id="const-FORMAT_WIDTH_SHORT"></span>`FORMAT_WIDTH_SHORT` | `'short'` | Available since 2.0.13. | `Formatter` |
| <span id="const-UNIT_LENGTH"></span>`UNIT_LENGTH` | `'length'` | Available since 2.0.13. | `Formatter` |
| <span id="const-UNIT_WEIGHT"></span>`UNIT_WEIGHT` | `'mass'` | Available since 2.0.13. | `Formatter` |

## Property details

### $booleanFormat <span id="property-booleanFormat"></span>

```php
public array $booleanFormat = null
```

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`](/docs/api/yii/i18n/formatter/index.md#property-locale).

### $calendar <span id="property-calendar"></span>

```php
public IntlCalendar|int|null $calendar = null
```

The calendar to be used for date formatting.

The value of this property will be directly
passed to the [constructor of the `IntlDateFormatter` class](https://www.php.net/manual/en/intldateformatter.create.php).

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](https://en.wikipedia.org/wiki/Jalali_calendar),
set this property to `\IntlDateFormatter::TRADITIONAL`.
The calendar must then be specified in the [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale), for example for the persian calendar the configuration for the formatter would be:

```
'formatter' => [
    'locale' => 'fa_IR@calendar=persian',
    'calendar' => \IntlDateFormatter::TRADITIONAL,
],
```

Available calendar names can be found in the [ICU manual](https://unicode-org.github.io/icu/userguide/datetime/calendar/).

Since PHP 5.5 you may also use an instance of the [`IntlCalendar`](https://www.php.net/manual/en/class.intlcalendar.php) class.
Check the [PHP manual](https://www.php.net/manual/en/intldateformatter.create.php) for more details.

If the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available, setting this property will have no effect.

**Since**

2.0.7

### $currencyCode <span id="property-currencyCode"></span>

```php
public string|null $currencyCode = null
```

The 3-letter ISO 4217 currency code indicating the default currency to use for [`asCurrency()`](/docs/api/yii/i18n/formatter/index.md#method-asCurrency).

If not set, the currency code corresponding to [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale) will be used.
Note that in this case the [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale) has to be specified with a country code, e.g. `en-US` otherwise it
is not possible to determine the default currency.

### $currencyDecimalSeparator <span id="property-currencyDecimalSeparator"></span>

```php
public string|null $currencyDecimalSeparator = null
```

The character displayed as the decimal point when formatting a currency.

If not set, the currency decimal separator corresponding to [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale) will be used.
If [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available, setting this property will have no effect.

**Since**

2.0.35

### $dateFormat <span id="property-dateFormat"></span>

```php
public string $dateFormat = 'medium'
```

The default format string to be used to format a [date](/docs/api/yii/i18n/formatter/index.md#method-asDate).

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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/).
Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the
PHP [date()](https://www.php.net/manual/en/function.date.php)-function.

For example:

```
'MM/dd/yyyy' // date in ICU format
'php:m/d/Y' // the same date in PHP format
```

### $datetimeFormat <span id="property-datetimeFormat"></span>

```php
public string $datetimeFormat = 'medium'
```

The default format string to be used to format a [date and time](/docs/api/yii/i18n/formatter/index.md#method-asDatetime).

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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/).

Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the
PHP [date()](https://www.php.net/manual/en/function.date.php) function.

For example:

```
'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 <span id="property-decimalSeparator"></span>

```php
public string|null $decimalSeparator = null
```

The character displayed as the decimal point when formatting a number.

If not set, the decimal separator corresponding to [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale) will be used.
If [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available, the default value is '.'.

### $defaultTimeZone <span id="property-defaultTimeZone"></span>

```php
public string $defaultTimeZone = 'UTC'
```

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](https://www.php.net/manual/en/timezones.php) 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.

Note that a UNIX timestamp is always in UTC by its definition. That means that specifying a default time zone different from
UTC has no effect on date values given as UNIX timestamp.

**Since**

2.0.1

### $language <span id="property-language"></span>

```php
public string|null $language = null
```

The language code (e.g. `en-US`, `en`) that is used to translate internal messages.

If not set, [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale) will be used (without the `@calendar` param, if included).

**Since**

2.0.28

### $locale <span id="property-locale"></span>

```php
public string|null $locale = null
```

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](https://www.php.net/manual/en/book.intl.php) is installed.
If not set, [`Application::$language`](/docs/api/yii/base/application/index.md#property-language) will be used.

### $measureUnits <span id="property-measureUnits"></span>

```php
public array $measureUnits = [self::UNIT_LENGTH => [self::UNIT_SYSTEM_IMPERIAL => ['inch' => 1, 'foot' => 12, 'yard' => 36, 'chain' => 792, 'furlong' => 7920, 'mile' => 63360], self::UNIT_SYSTEM_METRIC => ['millimeter' => 1, 'centimeter' => 10, 'meter' => 1000, 'kilometer' => 1000000]], self::UNIT_WEIGHT => [self::UNIT_SYSTEM_IMPERIAL => ['grain' => 1, 'drachm' => 27.34375, 'ounce' => 437.5, 'pound' => 7000, 'stone' => 98000, 'quarter' => 196000, 'hundredweight' => 784000, 'ton' => 15680000], self::UNIT_SYSTEM_METRIC => ['gram' => 1, 'kilogram' => 1000, 'ton' => 1000000]]]
```

Configuration of weight and length measurement units.

This array contains the most usable measurement units, but you can change it
in case you have some special requirements.

For example, you can add smaller measure unit:

```
$this->measureUnits[self::UNIT_LENGTH][self::UNIT_SYSTEM_METRIC] = [
    'nanometer' => 0.000001
]
```

**Since**

2.0.13

### $nullDisplay <span id="property-nullDisplay"></span>

```php
public string|null $nullDisplay = null
```

The text to be displayed when formatting a `null` value.

Defaults to `'<span class="not-set">(not set)</span>'`, where `(not set)`
will be translated according to [`$locale`](/docs/api/yii/i18n/formatter/index.md#property-locale).

### $numberFormatterOptions <span id="property-numberFormatterOptions"></span>

```php
public array $numberFormatterOptions = []
```

A list of name value pairs that are passed to the intl [NumberFormatter::setAttribute()](https://www.php.net/manual/en/numberformatter.setattribute.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter).

This property takes only effect if the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed.

Please refer to the [PHP manual](https://www.php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute)
for the possible options.

For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following:

```
[
    NumberFormatter::MIN_FRACTION_DIGITS => 0,
    NumberFormatter::MAX_FRACTION_DIGITS => 2,
]
```

### $numberFormatterSymbols <span id="property-numberFormatterSymbols"></span>

```php
public array $numberFormatterSymbols = []
```

A list of name value pairs that are passed to the intl [NumberFormatter::setSymbol()](https://www.php.net/manual/en/numberformatter.setsymbol.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter).

This property takes only effect if the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed.

Please refer to the [PHP manual](https://www.php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatsymbol)
for the possible options.

For example to choose a custom currency symbol, e.g. [U+20BD](https://unicode-table.com/en/20BD/) instead of `руб.` for Russian Ruble:

```
[
    NumberFormatter::CURRENCY_SYMBOL => '₽',
]
```

**Since**

2.0.4

### $numberFormatterTextOptions <span id="property-numberFormatterTextOptions"></span>

```php
public array $numberFormatterTextOptions = []
```

A list of name value pairs that are passed to the intl [NumberFormatter::setTextAttribute()](https://www.php.net/manual/en/numberformatter.settextattribute.php) method of all the number formatter objects created by [`createNumberFormatter()`](/docs/api/yii/i18n/formatter/index.md#method-createNumberFormatter).

This property takes only effect if the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is installed.

Please refer to the [PHP manual](https://www.php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute)
for the possible options.

For example to change the minus sign for negative numbers you can configure this property like the following:

```
[
    NumberFormatter::NEGATIVE_PREFIX => 'MINUS',
]
```

### $sizeFormatBase <span id="property-sizeFormatBase"></span>

```php
public int $sizeFormatBase = 1024
```

The base at which a kilobyte is calculated (1000 or 1024 bytes per kilobyte), used by [`asSize()`](/docs/api/yii/i18n/formatter/index.md#method-asSize) and [`asShortSize()`](/docs/api/yii/i18n/formatter/index.md#method-asShortSize).

Defaults to 1024.

### $systemOfUnits <span id="property-systemOfUnits"></span>

```php
public string $systemOfUnits = self::UNIT_SYSTEM_METRIC
```

Default system of measure units.

Defaults to [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC).
Possible values:
 - [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC)
 - [`UNIT_SYSTEM_IMPERIAL`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_IMPERIAL)

**Since**

2.0.13

### $thousandSeparator <span id="property-thousandSeparator"></span>

```php
public string|null $thousandSeparator = null
```

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`](/docs/api/yii/i18n/formatter/index.md#property-locale) will be used.
If [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available, the default value is ','.

### $timeFormat <span id="property-timeFormat"></span>

```php
public string $timeFormat = 'medium'
```

The default format string to be used to format a [time](/docs/api/yii/i18n/formatter/index.md#method-asTime).

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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/).
Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the
PHP [date()](https://www.php.net/manual/en/function.date.php)-function.

For example:

```
'HH:mm:ss' // time in ICU format
'php:H:i:s' // the same time in PHP format
```

### $timeZone <span id="property-timeZone"></span>

```php
public string|null $timeZone = null
```

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()](https://www.php.net/manual/en/function.date-default-timezone-set.php)
e.g. `UTC`, `Europe/Berlin` or `America/Chicago`.
Refer to the [php manual](https://www.php.net/manual/en/timezones.php) for available time zones.
If this property is not set, [`Application::$timeZone`](/docs/api/yii/base/application/index.md#property-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`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) accordingly.

## Method details

### asBoolean() <span id="method-asBoolean"></span>

```php
public function asBoolean(mixed $value): string
```

Formats the value as a boolean.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |

**Returns**

`string`: The formatted result.

**See also**

- [`$booleanFormat`](/docs/api/yii/i18n/formatter/index.md#property-booleanFormat)

### asCurrency() <span id="method-asCurrency"></span>

```php
public function asCurrency(mixed $value, string|null $currency = null, array $options = [], array $textOptions = []): string
```

Formats the value as a currency number.

This function does not require the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) to be installed
to work, but it is highly recommended to install it to get good formatting results.

Since 2.0.16 numbers that are mispresented after normalization are formatted as strings using fallback function
without PHP intl extension support. For very big numbers it's recommended to pass them as strings and not use
scientific notation otherwise the output might be wrong.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$currency` | `string\|null` | The 3-letter ISO 4217 currency code indicating the currency to use. If null, [`$currencyCode`](/docs/api/yii/i18n/formatter/index.md#property-currencyCode) will be used. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if no currency is given and [`$currencyCode`](/docs/api/yii/i18n/formatter/index.md#property-currencyCode) is not defined.

### asDate() <span id="method-asDate"></span>

```php
public function asDate(int|string|DateTime|DateTimeInterface|null $value, string|null $format = null): string
```

Formats the value as a date.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | The value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. - a string that can be [parsed to create a DateTime object](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.php.net/manual/en/class.datetime.php) object. You may set the time zone for the DateTime object to specify the source time zone. The formatter will convert date values according to [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) before formatting it. If no timezone conversion should be performed, you need to set [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) and [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) to the same value. Also no conversion will be performed on values that have no time information, e.g. `"2017-06-05"`. |
| `$format` | `string\|null` | The format used to convert the value into a date string. If null, [`$dateFormat`](/docs/api/yii/i18n/formatter/index.md#property-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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](https://www.php.net/manual/en/function.date.php)-function. |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value can not be evaluated as a date value.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the date format is invalid.

**See also**

- [`$dateFormat`](/docs/api/yii/i18n/formatter/index.md#property-dateFormat)

### asDatetime() <span id="method-asDatetime"></span>

```php
public function asDatetime(int|string|DateTime|DateTimeInterface|null $value, string|null $format = null): string
```

Formats the value as a datetime.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | The value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. - a string that can be [parsed to create a DateTime object](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.php.net/manual/en/class.datetime.php) object. You may set the time zone for the DateTime object to specify the source time zone. The formatter will convert date values according to [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) before formatting it. If no timezone conversion should be performed, you need to set [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) and [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) to the same value. |
| `$format` | `string\|null` | The format used to convert the value into a date string. If null, [`$datetimeFormat`](/docs/api/yii/i18n/formatter/index.md#property-datetimeFormat) 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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](https://www.php.net/manual/en/function.date.php)-function. |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value can not be evaluated as a date value.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the date format is invalid.

**See also**

- [`$datetimeFormat`](/docs/api/yii/i18n/formatter/index.md#property-datetimeFormat)

### asDecimal() <span id="method-asDecimal"></span>

```php
public function asDecimal(mixed $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a decimal number.

Property [`$decimalSeparator`](/docs/api/yii/i18n/formatter/index.md#property-decimalSeparator) will be used to represent the decimal point. The
value is rounded automatically to the defined decimal digits.

Since 2.0.16 numbers that are mispresented after normalization are formatted as strings using fallback function
without [PHP intl extension](https://www.php.net/manual/en/book.intl.php) support. For very big numbers it's
recommended to pass them as strings and not use scientific notation otherwise the output might be wrong.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. If not given, the number of digits depends in the input value and is determined based on `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION_DIGITS`, which can be configured using [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). If the PHP intl extension is not available, the default value is `2`. If you want consistent behavior between environments where intl is available and not, you should explicitly specify a value here. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

**See also**

- [`$decimalSeparator`](/docs/api/yii/i18n/formatter/index.md#property-decimalSeparator)
- [`$thousandSeparator`](/docs/api/yii/i18n/formatter/index.md#property-thousandSeparator)

### asDuration() <span id="method-asDuration"></span>

```php
public function asDuration(DateInterval|string|int|null $value, string $implodeString = ', ', string $negativeSign = '-'): string
```

Represents the value as duration in human readable format.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | [`DateInterval`](https://www.php.net/manual/en/class.dateinterval.php)`\|string\|int\|null` | The value to be formatted. Acceptable formats: - [DateInterval object](https://www.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 `-`. |

**Returns**

`string`: The formatted duration.

**Since**

2.0.7

### asEmail() <span id="method-asEmail"></span>

```php
public function asEmail(string|null $value, array $options = []): string
```

Formats the value as a mailto link.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | The value to be formatted. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`Html::mailto()`](/docs/api/yii/helpers/basehtml/index.md#method-mailto). |

**Returns**

`string`: The formatted result.

### asHtml() <span id="method-asHtml"></span>

```php
public function asHtml(string|null $value, array|null $config = null): string
```

Formats the value as HTML text.

The value will be purified using [`HtmlPurifier`](/docs/api/yii/helpers/htmlpurifier/index.md) to avoid XSS attacks.
Use [`asRaw()`](/docs/api/yii/i18n/formatter/index.md#method-asRaw) if you do not want any purification of the value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | The value to be formatted. |
| `$config` | `array\|null` | The configuration for the HTMLPurifier class. |

**Returns**

`string`: The formatted result.

### asImage() <span id="method-asImage"></span>

```php
public function asImage(mixed $value, array $options = []): string
```

Formats the value as an image tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`Html::img()`](/docs/api/yii/helpers/basehtml/index.md#method-img). |

**Returns**

`string`: The formatted result.

### asInteger() <span id="method-asInteger"></span>

```php
public function asInteger(mixed $value, array $options = [], array $textOptions = []): string
```

Formats the value as an integer number by removing any decimal digits without rounding.

Since 2.0.16 numbers that are mispresented after normalization are formatted as strings using fallback function
without [PHP intl extension](https://www.php.net/manual/en/book.intl.php) support. For very big numbers it's
recommended to pass them as strings and not use scientific notation otherwise the output might be wrong.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

### asLength() <span id="method-asLength"></span>

```php
public function asLength(float|int $value, int|null $decimals = null, array $numberOptions = [], array $textOptions = []): string
```

Formats the value as a length in human readable form for example `12 meters`.

Check properties [`$baseUnits`](/docs/api/yii/i18n/formatter/index.md#property-baseUnits) if you need to change unit of value as the multiplier
of the smallest unit and [`$systemOfUnits`](/docs/api/yii/i18n/formatter/index.md#property-systemOfUnits) to switch between [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC) or [`UNIT_SYSTEM_IMPERIAL`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_IMPERIAL).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int` | Value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$numberOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when INTL is not installed or does not contain required information.

**Since**

2.0.13

**See also**

- [`asLength()`](/docs/api/yii/i18n/formatter/index.md#method-asLength)

### asNtext() <span id="method-asNtext"></span>

```php
public function asNtext(string|null $value): string
```

Formats the value as an HTML-encoded plain text with newlines converted into breaks.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | The value to be formatted. |

**Returns**

`string`: The formatted result.

### asOrdinal() <span id="method-asOrdinal"></span>

```php
public function asOrdinal(mixed $value): string
```

Formats the value as a ordinal value of a number.

This function requires the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) to be installed.

This formatter does not work well with very big numbers.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available.

### asParagraphs() <span id="method-asParagraphs"></span>

```php
public function asParagraphs(string|null $value): string
```

Formats the value as HTML-encoded text paragraphs.

Each text paragraph is enclosed within a `<p>` tag.
One or multiple consecutive empty lines divide two paragraphs.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | The value to be formatted. |

**Returns**

`string`: The formatted result.

### asPercent() <span id="method-asPercent"></span>

```php
public function asPercent(mixed $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a percent number with "%" sign.

Since 2.0.16 numbers that are mispresented after normalization are formatted as strings using fallback function
without [PHP intl extension](https://www.php.net/manual/en/book.intl.php) support. For very big numbers it's
recommended to pass them as strings and not use scientific notation otherwise the output might be wrong.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. It must be a factor e.g. `0.75` will result in `75%`. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. If not given, the number of digits depends in the input value and is determined based on `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION_DIGITS`, which can be configured using [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). If the PHP intl extension is not available, the default value is `0`. If you want consistent behavior between environments where intl is available and not, you should explicitly specify a value here. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

### asRaw() <span id="method-asRaw"></span>

```php
public function asRaw(mixed $value): string
```

Formats the value as is without any formatting.

This method simply returns back the parameter without any format.
The only exception is a `null` value which will be formatted using [`$nullDisplay`](/docs/api/yii/i18n/formatter/index.md#property-nullDisplay).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |

**Returns**

`string`: The formatted result.

### asRelativeTime() <span id="method-asRelativeTime"></span>

```php
public function asRelativeTime(int|string|DateTime|DateTimeInterface|DateInterval|null $value, int|string|DateTime|DateTimeInterface|null $referenceTime = null): string
```

Formats the value as the time interval between a date and now in human readable form.

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.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|`[`DateInterval`](https://www.php.net/manual/en/class.dateinterval.php)`\|null` | 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](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.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` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | If specified the value is used as a reference time instead of `now` when `$value` is not a `DateInterval` object. |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value can not be evaluated as a date value.

### asScientific() <span id="method-asScientific"></span>

```php
public function asScientific(mixed $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a scientific number.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. If not given, the number of digits depends in the input value and is determined based on `NumberFormatter::MIN_FRACTION_DIGITS` and `NumberFormatter::MAX_FRACTION_DIGITS`, which can be configured using [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). If the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available, the default value depends on your PHP configuration. If you want consistent behavior between environments where intl is available and not, you should explicitly specify a value here. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

### asShortLength() <span id="method-asShortLength"></span>

```php
public function asShortLength(float|int $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a length in human readable form for example `12 m`.

This is the short form of [`asLength()`](/docs/api/yii/i18n/formatter/index.md#method-asLength).

Check properties [`$baseUnits`](/docs/api/yii/i18n/formatter/index.md#property-baseUnits) if you need to change unit of value as the multiplier
of the smallest unit and [`$systemOfUnits`](/docs/api/yii/i18n/formatter/index.md#property-systemOfUnits) to switch between [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC) or [`UNIT_SYSTEM_IMPERIAL`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_IMPERIAL).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int` | Value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when INTL is not installed or does not contain required information.

**Since**

2.0.13

**See also**

- [`asLength()`](/docs/api/yii/i18n/formatter/index.md#method-asLength)

### asShortSize() <span id="method-asShortSize"></span>

```php
public function asShortSize(string|int|float|null $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value in bytes as a size in human readable form for example `12 kB`.

This is the short form of [`asSize()`](/docs/api/yii/i18n/formatter/index.md#method-asSize).

If [`$sizeFormatBase`](/docs/api/yii/i18n/formatter/index.md#property-sizeFormatBase) is 1024, [binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...)
are used in the formatting result.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float\|null` | Value in bytes to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

**See also**

- [`$sizeFormatBase`](/docs/api/yii/i18n/formatter/index.md#property-sizeFormatBase)
- [`asSize()`](/docs/api/yii/i18n/formatter/index.md#method-asSize)

### asShortWeight() <span id="method-asShortWeight"></span>

```php
public function asShortWeight(float|int $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a weight in human readable form for example `12 kg`.

This is the short form of [`asWeight()`](/docs/api/yii/i18n/formatter/index.md#method-asWeight).

Check properties [`$baseUnits`](/docs/api/yii/i18n/formatter/index.md#property-baseUnits) if you need to change unit of value as the multiplier
of the smallest unit and [`$systemOfUnits`](/docs/api/yii/i18n/formatter/index.md#property-systemOfUnits) to switch between [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC) or [`UNIT_SYSTEM_IMPERIAL`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_IMPERIAL).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int` | Value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when INTL is not installed or does not contain required information.

**Since**

2.0.13

### asSize() <span id="method-asSize"></span>

```php
public function asSize(string|int|float|null $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value in bytes as a size in human readable form, for example `12 kilobytes`.

If [`$sizeFormatBase`](/docs/api/yii/i18n/formatter/index.md#property-sizeFormatBase) is 1024, [binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) (e.g. kibibyte/KiB, mebibyte/MiB, ...)
are used in the formatting result.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float\|null` | Value in bytes to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

**See also**

- [`$sizeFormatBase`](/docs/api/yii/i18n/formatter/index.md#property-sizeFormatBase)
- [`asShortSize()`](/docs/api/yii/i18n/formatter/index.md#method-asShortSize)

### asSpellout() <span id="method-asSpellout"></span>

```php
public function asSpellout(mixed $value): string
```

Formats the value as a number spellout.

This function requires the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) to be installed.

This formatter does not work well with very big numbers.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the [PHP intl extension](https://www.php.net/manual/en/book.intl.php) is not available.

### asText() <span id="method-asText"></span>

```php
public function asText(string|null $value): string
```

Formats the value as an HTML-encoded plain text.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | The value to be formatted. |

**Returns**

`string`: The formatted result.

### asTime() <span id="method-asTime"></span>

```php
public function asTime(int|string|DateTime|DateTimeInterface|null $value, string|null $format = null): string
```

Formats the value as a time.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | The value to be formatted. The following types of value are supported: - an integer representing a UNIX timestamp. A UNIX timestamp is always in UTC by its definition. - a string that can be [parsed to create a DateTime object](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.php.net/manual/en/class.datetime.php) object. You may set the time zone for the DateTime object to specify the source time zone. The formatter will convert date values according to [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) before formatting it. If no timezone conversion should be performed, you need to set [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) and [`$timeZone`](/docs/api/yii/i18n/formatter/index.md#property-timeZone) to the same value. |
| `$format` | `string\|null` | The format used to convert the value into a date string. If null, [`$timeFormat`](/docs/api/yii/i18n/formatter/index.md#property-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](https://unicode-org.github.io/icu/userguide/format_parse/datetime/). Alternatively this can be a string prefixed with `php:` representing a format that can be recognized by the PHP [date()](https://www.php.net/manual/en/function.date.php)-function. |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value can not be evaluated as a date value.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the date format is invalid.

**See also**

- [`$timeFormat`](/docs/api/yii/i18n/formatter/index.md#property-timeFormat)

### asTimestamp() <span id="method-asTimestamp"></span>

```php
public function asTimestamp(int|string|DateTime|DateTimeInterface|null $value): string
```

Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | 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](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.php.net/manual/en/class.datetime.php) object |

**Returns**

`string`: The formatted result.

### asUrl() <span id="method-asUrl"></span>

```php
public function asUrl(mixed $value, array $options = []): string
```

Formats the value as a hyperlink.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$options` | `array` | The tag options in terms of name-value pairs. See [`Html::a()`](/docs/api/yii/helpers/basehtml/index.md#method-a). Since 2.0.43 there is a special option available `scheme` - if set it won't be passed to [`Html::a()`](/docs/api/yii/helpers/basehtml/index.md#method-a) but it will control the URL protocol part of the link by normalizing URL and ensuring that it uses specified scheme. See [`Url::ensureScheme()`](/docs/api/yii/helpers/baseurl/index.md#method-ensureScheme). If `scheme` is not set the original behavior is preserved which is to add "http://" prefix when "://" string is not found in the $value. |

**Returns**

`string`: The formatted result.

### asWeight() <span id="method-asWeight"></span>

```php
public function asWeight(float|int $value, int|null $decimals = null, array $options = [], array $textOptions = []): string
```

Formats the value as a weight in human readable form for example `12 kilograms`.

Check properties [`$baseUnits`](/docs/api/yii/i18n/formatter/index.md#property-baseUnits) if you need to change unit of value as the multiplier
of the smallest unit and [`$systemOfUnits`](/docs/api/yii/i18n/formatter/index.md#property-systemOfUnits) to switch between [`UNIT_SYSTEM_METRIC`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_METRIC) or [`UNIT_SYSTEM_IMPERIAL`](/docs/api/yii/i18n/formatter/index.md#const-UNIT_SYSTEM_IMPERIAL).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int` | Value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when INTL is not installed or does not contain required information.

**Since**

2.0.13

### format() <span id="method-format"></span>

```php
public function format(mixed $value, string|array|Closure $format): string
```

Formats the value based on the given format type.

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 [`asHtml()`](/docs/api/yii/i18n/formatter/index.md#method-asHtml) will be used. Format names are case insensitive.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to be formatted. |
| `$format` | `string\|array\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | The format of the value, e.g., "html", "text" or an anonymous function returning the formatted value. 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')`. The anonymous function signature should be: `function($value, $formatter)`, where `$value` is the value that should be formatted and `$formatter` is an instance of the Formatter class, which can be used to call other formatting functions. The possibility to use an anonymous function is available since version 2.0.13. |

**Returns**

`string`: The formatting result.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the format type is not supported by this class.

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the
given configuration.

**Returns**

`mixed`

### asCurrencyStringFallback() <span id="method-asCurrencyStringFallback"></span>

```php
protected function asCurrencyStringFallback(string|int|float $value, string|null $currency = null): string
```

Fallback for formatting value as a currency number.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float` | The value to be formatted. |
| `$currency` | `string\|null` | The 3-letter ISO 4217 currency code indicating the currency to use. If null, [`$currencyCode`](/docs/api/yii/i18n/formatter/index.md#property-currencyCode) will be used. |

**Returns**

`string`: The formatted result.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if no currency is given and [`$currencyCode`](/docs/api/yii/i18n/formatter/index.md#property-currencyCode) is not defined.

**Since**

2.0.16

### asDecimalStringFallback() <span id="method-asDecimalStringFallback"></span>

```php
protected function asDecimalStringFallback(string|int|float $value, int|null $decimals = 2): string
```

Fallback for formatting value as a decimal number.

Property [`$decimalSeparator`](/docs/api/yii/i18n/formatter/index.md#property-decimalSeparator) will be used to represent the decimal point. The value is rounded automatically
to the defined decimal digits.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float` | The value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. The default value is `2`. |

**Returns**

`string`: The formatted result.

**Since**

2.0.16

**See also**

- [`$decimalSeparator`](/docs/api/yii/i18n/formatter/index.md#property-decimalSeparator)
- [`$thousandSeparator`](/docs/api/yii/i18n/formatter/index.md#property-thousandSeparator)

### asIntegerStringFallback() <span id="method-asIntegerStringFallback"></span>

```php
protected function asIntegerStringFallback(string|int|float $value): string
```

Fallback for formatting value as an integer number by removing any decimal digits without rounding.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float` | The value to be formatted. |

**Returns**

`string`: The formatted result.

**Since**

2.0.16

### asPercentStringFallback() <span id="method-asPercentStringFallback"></span>

```php
protected function asPercentStringFallback(string|int|float $value, int|null $decimals = null): string
```

Fallback for formatting value as a percent number with "%" sign.

Property [`$decimalSeparator`](/docs/api/yii/i18n/formatter/index.md#property-decimalSeparator) will be used to represent the decimal point. The value is rounded automatically
to the defined decimal digits.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float` | The value to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point. The default value is `0`. |

**Returns**

`string`: The formatted result.

**Since**

2.0.16

### createNumberFormatter() <span id="method-createNumberFormatter"></span>

```php
protected function createNumberFormatter(int $style, int|null $decimals = null, array $options = [], array $textOptions = []): NumberFormatter
```

Creates a number formatter based on the given type and format.

You may override this method to create a number formatter based on patterns.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$style` | `int` | The type of the number formatter. Values: NumberFormatter::DECIMAL, ::CURRENCY, ::PERCENT, ::SCIENTIFIC, ::SPELLOUT, ::ORDINAL ::DURATION, ::PATTERN_RULEBASED, ::DEFAULT_STYLE, ::IGNORE |
| `$decimals` | `int\|null` | The number of digits after the decimal point. |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

[`NumberFormatter`](https://www.php.net/manual/en/class.numberformatter.php): The created formatter instance

### formatNumber() <span id="method-formatNumber"></span>

```php
protected function formatNumber(string|int|float $value, int|null $decimals, int $maxPosition, array|int $formatBase, array $options, array $textOptions): array
```

Given the value in bytes formats number part of the human readable form.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|int\|float` | Value in bytes to be formatted. |
| `$decimals` | `int\|null` | The number of digits after the decimal point |
| `$maxPosition` | `int` | Maximum internal position of size unit, ignored if $formatBase is an array |
| `$formatBase` | `array\|int` | The base at which each next unit is calculated, either 1000 or 1024, or an array |
| `$options` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterOptions). |
| `$textOptions` | `array` | Optional configuration for the number formatter. This parameter will be merged with [`$numberFormatterTextOptions`](/docs/api/yii/i18n/formatter/index.md#property-numberFormatterTextOptions). |

**Returns**

`array`: [parameters for Yii::t containing formatted number, internal position of size unit]

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric or the formatting failed.

**Since**

2.0.32

### isNormalizedValueMispresented() <span id="method-isNormalizedValueMispresented"></span>

```php
protected function isNormalizedValueMispresented(string|float|int $value, float|int $normalizedValue): bool
```

Checks if string representations of given value and its normalized version are different.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|float\|int` |  |
| `$normalizedValue` | `float\|int` |  |

**Returns**

`bool`

**Since**

2.0.16

### normalizeDatetimeValue() <span id="method-normalizeDatetimeValue"></span>

```php
protected function normalizeDatetimeValue(int|string|DateTime|DateTimeInterface|null $value, bool $checkDateTimeInfo = false): DateTime|array
```

Normalizes the given datetime value as a DateTime object that can be taken by various date/time formatting methods.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`\|`[`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php)`\|null` | 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](https://www.php.net/manual/en/datetime.formats.php). The timestamp is assumed to be in [`$defaultTimeZone`](/docs/api/yii/i18n/formatter/index.md#property-defaultTimeZone) unless a time zone is explicitly given. - a PHP [DateTime](https://www.php.net/manual/en/class.datetime.php) object |
| `$checkDateTimeInfo` | `bool` | Whether to also check if the date/time value has some time and date information attached. Defaults to `false`. If `true`, the method will then return an array with the first element being the normalized timestamp, the second a boolean indicating whether the timestamp has time information and third a boolean indicating whether the timestamp has date information. This parameter is available since version 2.0.1. |

**Returns**

[`DateTime`](https://www.php.net/manual/en/class.datetime.php)`|array`: The normalized datetime value Since version 2.0.1 this may also return an array if `$checkDateTimeInfo` 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. Since version 2.0.12 the array has third boolean element indicating whether the timestamp has date information or it is just a time value.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value can not be evaluated as a date value.

### normalizeNumericStringValue() <span id="method-normalizeNumericStringValue"></span>

```php
protected function normalizeNumericStringValue(string $value): string
```

Normalizes a numeric string value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string` |  |

**Returns**

`string`: The normalized number value as a string

**Since**

2.0.16

### normalizeNumericValue() <span id="method-normalizeNumericValue"></span>

```php
protected function normalizeNumericValue(mixed $value): float|int
```

Normalizes a numeric input value.

- everything [empty](https://www.php.net/manual/en/function.empty.php) will result in `0`
- a [numeric](https://www.php.net/manual/en/function.is-numeric.php) string will be casted to float
- everything else will be returned if it is [numeric](https://www.php.net/manual/en/function.is-numeric.php),
  otherwise an exception is thrown.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The input value |

**Returns**

`float|int`: The normalized number value

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the input value is not numeric.