JavaScript

Format Currency

by @admin
12h ago
Apr 28, 2026
Public
Formats a number as a locale-aware currency string using the built-in Intl.NumberFormat API. Supports any ISO 4217 currency code and any BCP 47 locale tag. No external library required — handles symbol placement, thousands separators, and decimal places automatically per locale rules.
JavaScript
function formatCurrency(amount, currency = 'USD', locale = 'en-US') {
  return new Intl.NumberFormat(locale, {
    style: 'currency',
    currency,
    minimumFractionDigits: 2,
    maximumFractionDigits: 2,
  }).format(amount);
}

// Usage
console.log(formatCurrency(1234.5));              // $1,234.50
console.log(formatCurrency(1234.5, 'EUR', 'de-DE')); // 1.234,50 €
console.log(formatCurrency(9999.99, 'GBP', 'en-GB')); // £9,999.99
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.