Money
An operations agent keeps amounts exactly, as Decimal, in the currency each
Change gives or the service’s currency. Amounts in different currencies
are never added together. After a second change that moves money, the model is told
what the call comes to, per currency. Each settled change in the call’s
record carries its money as an exact decimal string and its currency.
Change.money: one amount per write, as anint,float, numericstr, orDecimal. More than 0 is charged; less than 0 goes back to the caller.Change.currency: the change’s ISO 4217 code, defaulting to the service’s.currency=onOperationsorServiceAgent: the default code, checked to be three capital letters (ValueErrorotherwise).money_format=onOperationsorServiceAgent:fn(amount, currency)replacesformat_moneyfor the totals the service states.amountis aDecimal, never below 0, andcurrencyis the code orNone.
format_money
format_money(amount, currency=None) returns an amount as the model reads it, with
the currency’s symbol or code and its own decimal places: $54.04, €54.04,
¥5,404, KWD 1.235. A code that isn’t in CURRENCIES goes after the amount
(54.04 XOF). With no currency, the number stands alone, with cents only when it has
any.
Parameters
amount
The amount. A bool, a non-numeric string, or a non-finite value raises an error.
currency
The ISO 4217 code. Must be three capital letters, or ValueError is raised.
Returns
str
CURRENCIES
A read-only mapping of 36 ISO 4217 codes to (prefix, decimal places), such as
"USD": ("$", 2), "JPY": ("¥", 0), and "KWD": ("KWD ", 3). A symbol several
currencies share is written so it isn’t ambiguous (CA$, A$).