JavaScript

How to Format Number as Currency String in JavaScript

In this tutorial, we are going to see how to format numbers in currency format in Javascript. Sometimes you get a value in digits eg 8000 and you want to display them as a currency in your country eg “8000 €”.

Different countries have different formats for displaying currency in their locale. We can use the Intl.NumberFormat method to format the number in the currency of any country.
 

Format the number in EURO
const euro = new Intl.NumberFormat('fr-FR', {
  style: 'currency',
  currency: 'EUR',
  minimumFractionDigits: 2
});

console.log(euro.format(8000)); 
console.log(euro.format(25));
console.log(euro.format(99600023147));

Output:

8 000,00 €
25,00 €
99 600 023 147,00 €

 

 

Format the number in USD
const usd = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
  minimumFractionDigits: 2
});

console.log(usd.format(8000)); 
console.log(usd.format(25));
console.log(usd.format(99600023147));

Output:

$8,000.00
$25.00
$99,600,023,147.00

You can read more about the different options available on Intl.NumberFormat.
 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *