Format currency in Javascript

We can use Number.prototype.toLocaleString() with the en-US locale and the currency option set to USD.:

JavascriptIcon
const amount = 1234567.89;
 
const formatted = amount.toLocaleString("en-US", {
  style: "currency",
  currency: "USD",
});
// Output: "$1,234,567.89"
Explanation:
  • "en-US" → formats according to U.S. conventions.
  • style: "currency" → tells it to format as money.
  • currency: "USD" → specifies U.S. dollars.