Arithmetic operations with floats are not directly supported. If you need to operate with floats, you must first convert the float to a Decimal, or the Money object to a float (i.e. float(m)). Please be aware of the issues and limitations of floating point arithmetics.

Formatting

Money objects are printed by default with en_US formatting and the currency code.

>>>m=Money('1234.567','EUR')>>>str(m)'EUR 1,234.57'

Use format(locale=DEFAULT_LC_NUMERIC, pattern=None) for locale-aware formatting with currency expansion. format() emulates babel.numbers.format_currency(), and requires Babel to be installed:

Currency exchange

Currency exchange works by “installing” a backend class that implements the abstract base class (abc) money.exchange.BackendBase. Its API is exposed through money.xrates, along with setup functions xrates.install(pythonpath), xrates.uninstall(), and xrates.backend_name.

Differences between Python versions

Returns EUR 2, a Money object with rounded amount to the nearest even.

Design decisions

There are several design decisions in money that differ from currently available money class implementations:

Localization

Do not keep any kind of locale conventions database inside this package. Locale conventions are extensive and change over time; keeping track of them is a project of its own. There is already such a project and database (the Unicode Common Locale Data Repository), and an excellent python API for it: Babel.

Currency

There is no need for a currency class. A currency is fully identified by its ISO 4217 code, and localization or exchange rates data are expected to be centralized as databases/services because of their changing nature.

Also:

Modulo operator (%): do not override to mean “percentage”.

Numeric type: you can mix numbers and money in binary operations, and objects evaluate to False if their amount is zero.