The Money type pairs a currency code with an exact Decimal amount. Arithmetic on Money values enforces matching currencies at runtime.
from money import of
from decimal import parse
let price = of("USD", parse("29.99").unwrap())
let tax = of("USD", parse("2.40").unwrap())
let total = price + tax # Money(USD, 32.39)
print(total)
| Function | Returns | Description |
|---|---|---|
of(currency, amount) | Money | Create from currency code and Decimal amount |
| Method | Returns | Description |
|---|---|---|
.currency | Str | The currency code (e.g., "USD") |
.amount | Decimal | The decimal amount |
Money supports + and - between values of the same currency, and comparison operators.