Format Currency with Intl
Format Currency with Intl is a reusable JavaScript snippet. Formats numbers as currency strings using the Intl.NumberFormat API. Supports any locale and currency code. The full implementation: const currency = (value, locale = 'en-US', currencyCode = 'USD') => new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode, minimumFractionDigits: 2, maximumFractionDigits: 2, }).format(value) // Shorthand for common currencies const usd = v => currency(v, 'en-US', 'USD') const eur = v => currency(v, 'de-DE', 'EUR') const gbp = v => currency(v, 'en-GB', 'GBP') const jpy = v => currency(v, 'ja-JP', 'JPY') const cny = v => currency(v, 'zh-CN', 'CNY') // Usage usd(1234.5) // "$1,234.50" eur(1234.5) // "1.234,50 €" jpy(1234) // "¥1,234"… This snippet uses only standard JavaScript with no dependencies, so it runs in modern browsers and Node.js alike. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.