Revision #33 has been created by rackycz on Oct 3, 2020, 4:30:14 PM with the memo:
Decimal Integer formatter
« previous (#32) next (#34) »
Changes
Title
unchanged
Yii v2 snippet guide II
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
tutorial,beginner,yii2,snippets
Content
changed
[...]
**Custom formatter - asDecimalOrInteger **
---
If I generate a PDF-invoice it contains many numbers and it is nice to print them as integers when decimals are not needed. For example number 24 looks better and saves space compared to 24.00. So I created such a formatter. Original inspiration and how-to was found here:
- https://stackoverflow.com/questions/46089960/yii2-formatter-create-custom-format
- ... thanks to karpy47
My formatter looks like this:[...]
```
Usage is simple. Read the link above and give like to karpy47 or see below:
```php
'components' => [
'formatter' => [
'class' => 'app\myHelpers\MyFormatter',
],
],
```
There is only one formatter in the whole of Yii and you can extend id = you can add more methods and the rest of the formatter will remain so you can use all other methods as mentioned in documentation.