What is the best way to convert a number into a formatted currency string using JavaScript?

If you prefer doing things manually (say you’re not targeting multiple locales), here’s a basic approach using toFixed and some string trickery:

function formatCurrency(amount) {
  return "$ " + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}

console.log(formatCurrency(2500)); // $ 2,500.00

While this method doesn’t use Intl, it works well when you need a lightweight javascript format currency approach without relying on built-in internationalization.