Skip to content
/ money Public

A Money class written in C# for handling multi-currency arithmetic with generic type support.

License

Notifications You must be signed in to change notification settings

zpbappi/money

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

money Build status

Yet another money class written in C#.

Features at a glance

  • 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

Supported operations

  • unary_operator Money
  • Money unary_operator
  • number binary_operator Money
  • Money binary_operator number
  • Money comparison_operator Money
  • Money binary_operator Money

Usage

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.

About

A Money class written in C# for handling multi-currency arithmetic with generic type support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages