Skip to navigation

say_money

View as MarkdownOpen in Claude

Return an amount of money in words. The amount is rounded to the currency’s smallest unit, half up. A whole amount has no minor part (“one dollar”), an amount under one major unit has no major part (“five cents”), and a negative amount starts with “minus”.

from signalwire.speech import say_money

Parameters

amount
float | int | str | DecimalRequired

The amount in the currency’s major unit: dollars, not cents. Raises ValueError for a value that isn’t a finite number, including a bool.

currency
strDefaults to USD

The ISO 4217 code, in any case. One of USD, CAD, AUD, NZD, EUR, GBP, MXN, INR, or JPY; any other code raises ValueError. JPY has no minor unit, so the amount rounds to whole yen.

Returns

str — The amount in words, such as "fourteen dollars and fifty cents".

Raises

ValueError for an amount that isn’t a number, or a currency not listed above.

Example

from signalwire.speech import say_money
print(say_money(14.5))
# fourteen dollars and fifty cents
print(say_money("1.005"))
# one dollar and one cent
print(say_money(-2.01, "GBP"))
# minus two pounds and one penny
print(say_money(1200, "JPY"))
# one thousand two hundred yen

Part of the speech helpers module.