Abbreviate number in Kilo(K) and Million(M) using filter in Vue.js
In this article, we are going to learn how to abbreviate a number using filters in VueJS. Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data.
Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filter is a function that accepts a value and returns another value. The returned value is the one that’s actually printed in the Vue.js template.
The abbreviation of numbers in kilo(K) and million(M) can be performed using filters. We first check if all the number is less than one million or greater. This can be done by using simple math logic or counting the length of the number by converting it to a string. If the number is less than a million then we divide it by 1000, otherwise, we divide the number by 1000000 and return the floor value of it along with the abbreviation needed.