Number pipe either 0 or 2 decimal places

橙三吉。 提交于 2019-12-04 16:37:20
Adam A

If you want to do more than one thing on your variable, the best practise is to create two diffrent pipes and use them together. Important is order from left to right. If you want to display only two digits you can use built-in pipes like deicmalPipe:

Angular Doc Or just check that topic: Stack overflow answer

If you want to display 1 not 1.00 you can create your custom pipe where it check if that characters are 00 or sth else. If it is 00 it return number without these digits.

For displaying 1 instead of 1.0 you can try this.

{{x | number:'1.0-0'}}
Sourav Raj

use :

{{ number | number : '1.2-2'}}

https://angular.io/api/common/DecimalPipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!