fmt_currency()

Format a number as a currency value.

Usage

Source

fmt_currency(
    x,
    *,
    currency="USD",
)

Parameters

x: float

The amount to format.

currency: str = "USD"
A three-letter currency code (case-insensitive). Yen values are shown without decimal places.

Returns

str
The formatted amount, with the currency symbol.

Examples

Amounts are in US dollars by default:

from tinytab import fmt_currency

fmt_currency(1234.5)
'$1,234.50'

Choose another currency with its three-letter code, in any case. Negative amounts put the sign before the symbol:

fmt_currency(-5, currency="gbp")
'-£5.00'

Yen are shown without decimal places:

fmt_currency(1234.5, currency="JPY")
'¥1,234'