Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.

Money

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)

Constructors

FunctionReturnsDescription
of(currency, amount)MoneyCreate from currency code and Decimal amount

Methods

MethodReturnsDescription
.currencyStrThe currency code (e.g., "USD")
.amountDecimalThe decimal amount

Money supports + and - between values of the same currency, and comparison operators.