How to Format a Number as Currency in JavaScript
Every country has its currency and different patterns or ways of displaying monetary amounts. When we appropriately express a number, it is easier to read and comprehend for readers.
When you use data from an API or an external resource, it will be in some generic format. For instance, if you are creating a store, you may have data such as pricing.
This article will walk you through how to format a number as Currency in JavaScript.
Let’s dive in!
We will be using a random number, such as 17225, as shown in the arrays below:
const Journals = [
  {
    “id”: 01,
    “name”: “Software Development”,
    “price”: 100.80,
  },
  {
    “id”: 02,
    “name”: “Introduction to Programming”,
    “price”: 1534,
  },
    {
    “id”: 04,
    “name”: “Program or Be Programmed”,
    “price”: 17225,
  }
]
const price = 17225;
let KenyaShilling = new Intl.NumberFormat(‘en-Ke’,
{
  style: ‘currency’,
  currency: ‘KSH’,
});
console.log(`The formatted version of {price} is {KenyaShilling.format(price)}`);
// The formatted version of 17225 is Ksh17,225.00