Yet another money class written in C#.
- Generic type for the amount of Money (including your custom type)
- Unary arithmetic
- Binary arithmetic with arbitrary numbers
- Operations involving money of same currency
- Operations involving money of different currencies
- unary_operator
Money
Money
unary_operatornumber
binary_operatorMoney
Money
binary_operatornumber
Money
comparison_operatorMoney
Money
binary_operatorMoney
Start by installing this nuget package.
Create:
// create money with decimal type of amount in my currency
var localMoney = new Money<decimal>(100m);
// create Australian dollars
var aud = new Money<decimal>(42m, "AUD");
Operate:
var m1 = Money<decimal>(100m, "AUD");
var m2 = Money<decimal>(-42m, "AUD");
var m3 = Money<decimal>(3.1415m, "USD");
var m4 = Money<decimal>(1m, "EUR");
var m5 = Money<decimal>(8m, "GBP");
var audWallet = m1 + m2;
var audWalletValueAsMoney = audWallet.EvaluateWithoutConversion();
var multinationalWallet = (m1 % m5) + ((m2 * 3.5m) / m4) - (m3 * 9m);
var currencyConverter = new MyCurrencyConverter(); // this is some imaginary implementation of ICurrencyConverter<T>
var resultingMoneyInAUD = multinationalWallet.Evaluate(currencyConverter, "AUD");
For better explanation of features and other examples, visit this blog post.