Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to show 1k,1M & 1B in numbers using Intl api in javascript?

How to show 1k,1M and 1B in numbers using Intl api in javascript?

let num = 1000;

if(num == 1000){

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading