Display number in billion, million, thousand using custom pipe in angular
In this article, we will create a custom reusable pipe in angular which will help us to display big numbers to short numbers with the suffix.
K for Thousand, M for Million, B for Billion and T for Trillion.
Let's start by creating a pipe. We can create a custom pipe using npm
ng g pipe numberSuffix pipe
Now, Change its content with the below code.
Now, update your html file where you want to use this pipe like below.
And it is done, your pipe is ready. :blush: :blush:
The special thing about this pipe is, it will handle negative numbers, the strings also.
{{ anyBigNumber | numberSuffix }}
You can check it like this.
{{ 12600000 | numberSuffix }} -> 13M{{ 12600000 | numberSuffix: 2 }} -> 12.60M{{ 12600 | numberSuffix: 2 }} -> 12.60K{{ 126 | numberSuffix }} -> 126
Please comment if you face any issues. Here are a few other articles. Check it out them also, these also will be useful to you.
Angular 9 new features. They will be useful for you in your next angular interview.
How to update your existing project to angular 5.
Top MNC Companies DevOps Interview questions.
Please comment if you face any issues. 😃 😃
Please Clap if you found these questions useful. 🙌 🙌 Happy coding. 😃 😃