For formatting of outputs Yii provides a formatter class to make data more readable for users.
For formatting of outputs Yii provides a formatter class to make data more readable for users.
[[yii\i18n\Formatter]] is a helper class that is registered as an [application component](structure-application-components.md) named `formatter` by default.
[[yii\i18n\Formatter]] is a helper class that is registered as an [application component](structure-application-components.md) named `formatter` by default.
It provides a set of methods for data formatting purpose such as date/time values, numbers and other commonly used formats in a localized way.
It provides a set of methods for data formatting purposes such as date/time values, numbers and other commonly used formats in a localized way.
The formatter can be used in two different ways.
The formatter can be used in two different ways:
1. Using the formatting methods (all formatter methods prefixed with `as`) directly:
1. Using the formatting methods (all formatter methods prefixed with `as`) directly:
...
@@ -32,11 +32,11 @@ The formatter can be used in two different ways.
...
@@ -32,11 +32,11 @@ The formatter can be used in two different ways.
For formatting numeric values the formatter class provides the following methods:
For formatting numeric values the formatter class provides the following methods:
- [[yii\i18n\Formatter::asInteger()|integer]] - the value is formatted as an integer e.g. `42`.
- [[yii\i18n\Formatter::asInteger()|integer]] - the value is formatted as an integer e.g. `42`.
- [[yii\i18n\Formatter::asDecimal()|decimal]] - the value is formatted as a decimal number considering decimal and thousand separators e.g. `42.123`.
- [[yii\i18n\Formatter::asDecimal()|decimal]] - the value is formatted as a decimal number considering decimal and thousand separators e.g. `2,542.123` or `2.542,123`.
- [[yii\i18n\Formatter::asPercent()|percent]] - the value is formatted as a percent number e.g. `42%`.
- [[yii\i18n\Formatter::asPercent()|percent]] - the value is formatted as a percent number e.g. `42%`.
- [[yii\i18n\Formatter::asScientific()|scientific]] - the value is formatted as a number in scientific format e.g. `4.2E4`.
- [[yii\i18n\Formatter::asScientific()|scientific]] - the value is formatted as a number in scientific format e.g. `4.2E4`.
- [[yii\i18n\Formatter::asCurrency()|currency]] - the value is formatted as a currency value e.g. `£420.00`.
- [[yii\i18n\Formatter::asCurrency()|currency]] - the value is formatted as a currency value e.g. `£420.00`.
...
@@ -153,7 +153,7 @@ The format for number formatting can be adjusted using the [[yii\i18n\Formatter:
...
@@ -153,7 +153,7 @@ The format for number formatting can be adjusted using the [[yii\i18n\Formatter:
For more advanced configuration, [[yii\i18n\Formatter::numberFormatterOptions]] and [[yii\i18n\Formatter::numberFormatterTextOptions]]
For more advanced configuration, [[yii\i18n\Formatter::numberFormatterOptions]] and [[yii\i18n\Formatter::numberFormatterTextOptions]]
can be used to configure the internally used [NumberFormatter class](http://php.net/manual/en/class.numberformatter.php)
can be used to configure the internally used [NumberFormatter class](http://php.net/manual/en/class.numberformatter.php)
For example to adjust the maximum and minimum value of fraction digits you can configure this property like the following:
For example, to adjust the maximum and minimum value of fraction digits you can configure this property like the following: