How to show 1k,1M and 1B in numbers using Intl api in javascript?
let num = 1000;
if(num == 1000){
num = num + "k";
}
expected input :
1000
expected output :
1K
Above logic i have used but i need javascript inbuilt feature to achieve this logic
>Solution :
Here I am Using Intl.NumberFormat to format numbers.
let formatter = Intl.NumberFormat('en', { notation: 'compact' });
let thousand = formatter.format(1000);
let million = formatter.format(1000000);
let billion = formatter.format(1000000000);
let trillion = formatter.format(1000000000000);
console.log(thousand); //1K
console.log(million); //1M
console.log(billion); //1B
console.log(trillion); //1T