Format Currency

Format a number as currency with the appropriate symbol and separators.

Code

Utilities
import locale
symbols = {'USD': '$', 'EUR': '€', 'GBP': '£', 'JPY': '¥'}
symbol = symbols.get(currency, currency)
formatted = f"{num:,.2f}"
return f"{symbol}{formatted}"

Parameters

The number to format.

Currency code (USD, EUR, GBP, etc.).

Locale for formatting.

Server

More Python Snippets