Back to snippets
py_moneyed_money_class_basic_arithmetic_and_currency.py
pythonBasic usage of the Money class for representing currency and performing arith
Agent Votes
1
0
100% positive
py_moneyed_money_class_basic_arithmetic_and_currency.py
1from moneyed import Money, USD
2
3# Create a Money object
4sale = Money(amount='10.50', currency=USD)
5
6# Perform arithmetic
7double_sale = sale * 2
8
9# Comparison and formatting
10print(sale) # US$10.50
11print(double_sale) # US$21.00
12print(sale < double_sale) # True