All Projects → DynamicHands → Nodamoney

DynamicHands / Nodamoney

Licence: apache-2.0
NodaMoney provides a library that treats Money as a first class citizen and handles all the ugly bits like currencies and formatting.

Projects that are alternatives of or similar to Nodamoney

monetized
A lightweight solution for handling and storing money.
Stars: ✭ 46 (-68.06%)
Mutual labels:  money, currencies
EasyMoney-Widgets
The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.
Stars: ✭ 91 (-36.81%)
Mutual labels:  money, currencies
stockholm
💵 Modern Python library for working with money and monetary amounts. Human friendly and flexible approach for development. 100% test coverage + built-in support for GraphQL and Protocol Buffers transports using current best-practices.
Stars: ✭ 26 (-81.94%)
Mutual labels:  money, currencies
Fixer
A foreign exchange rates and currency conversion API
Stars: ✭ 2,545 (+1667.36%)
Mutual labels:  currencies, money
Django Prices
Django fields for the prices module
Stars: ✭ 135 (-6.25%)
Mutual labels:  currencies, money
latinum
Latinum is a framework for resource and currency calculations.
Stars: ✭ 109 (-24.31%)
Mutual labels:  money, currencies
SimpleTypes
The universal PHP library to convert any values and measures (money, weight, currency converter, length, etc.).
Stars: ✭ 56 (-61.11%)
Mutual labels:  money, currencies
Prices
Python price handling for humans.
Stars: ✭ 248 (+72.22%)
Mutual labels:  currencies, money
react-local-currency
💵 💴Shows the price of your services in the customer's currency 💶 💷
Stars: ✭ 21 (-85.42%)
Mutual labels:  money, currencies
currency-converter
💰 Easily convert between 32 currencies
Stars: ✭ 16 (-88.89%)
Mutual labels:  money, currencies
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+16.67%)
Mutual labels:  currencies, money
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (-40.97%)
Mutual labels:  currencies, money
django-prices-openexchangerates
openexchangerates.org support for django-prices
Stars: ✭ 33 (-77.08%)
Mutual labels:  money, currencies
currency-conversion
Convert Money Amounts between currencies.
Stars: ✭ 19 (-86.81%)
Mutual labels:  money, currencies
Oxr
💱 Node.js wrapper for the Open Exchange Rates API
Stars: ✭ 72 (-50%)
Mutual labels:  currencies, money
Javamoney Lib
JavaMoney financial libraries, extending and complementing JSR 354
Stars: ✭ 104 (-27.78%)
Mutual labels:  currencies, money
Node Currency Swap
Currency Exchange Rates library for nodejs
Stars: ✭ 119 (-17.36%)
Mutual labels:  currencies
Eventflow.example
DDD+CQRS+Event-sourcing examples using EventFlow following CQRS-ES architecture. It is configured with RabbitMQ, MongoDB(Snapshot store), PostgreSQL(Read store), EventStore(GES). It's targeted to .Net Core 2.2 and include docker compose file.
Stars: ✭ 131 (-9.03%)
Mutual labels:  domain-driven-design
Java Ddd Example
☕🎯 Hexagonal Architecture + DDD + CQRS in a Java project using SpringBoot
Stars: ✭ 119 (-17.36%)
Mutual labels:  domain-driven-design
Neventlite
NEventLite - An extensible lightweight library for .NET that manages the Aggregate lifecycle in an Event Sourced system. Supports Event and Snapshot storage providers like EventStore/Redis or SQL Server. Built with dependency injection in mind and seamlessly integrates with AspNetCore.
Stars: ✭ 117 (-18.75%)
Mutual labels:  domain-driven-design

NodaMoney

You can get the latest stable release or prerelease from the official Nuget.org feed or from our github releases page.

If you'd like to work with the bleeding edge, you can use our custom Nuget feed. Packages on this feed are alpha and beta and, while they've passed all our tests, are not yet ready for production.

For support, bugs and new ideas use GitHub issues. Please see our guidelines for contributing to the NodaMoney.

Build status Coverage Status

See http://www.nodamoney.org/ for more information about this project or below.

About

NodaMoney provides a library that treats Money as a first class citizen in .NET and handles all the ugly bits like currencies and formatting.

We have the decimal type in .NET to store an amount of money, which can be used for very basic things. But it's still a numeric value without knowledge about its currency, major and minor units, formatting, etc. The .NET Framework has the System.Globalization namespace that helps with formatting of money in different cultures and regions, but it only captures some info about currencies, but not everything.

There is also some business logic surronding money, like dividing without losing pennies (like in the movie Office Space), conversion, etc. that motivates to have a Money type that contains all the domain logic, like Martin Fowler already descibed in his book Patterns of Enterprise Application Architecture

NodaMoney represents the .NET counterpart of java library JodaMoney, like NodaTime is the .NET counterpart of JodaTime. NodaMoney does not provide, nor is it intended to provide, monetary algorithms beyond the most basic and obvious. This is because the requirements for these algorithms vary widely between domains. This library is intended to act as the base layer, providing classes that should be in the .NET Framework. It complies with the currencies in ISO 4217.

Usage

At the moment there are four classes:

  • Currency: An immutable structure that represents a currency. It can give all ISO 4217 and custom currencies.
  • Money: An immutable structure that represents money in a specified currency.
  • ExchangeRate: A stucture that represents a currency pair that can convert money from one currency to another currency.
  • CurrencyBuilder: Defines a custom currency that is new or based on another currency.

Initalizing money

// define money with explicit currency
var euros = new Money(6.54m, Currency.FromCode("EUR"));
var euros = new Money(6.54m, "EUR");

// define money explicit using helper method for most used currencies in the world
var money = Money.Euro(6.54m);
var money = Money.USDollar(6.54m);
var money = Money.PoundSterling(6.54m);
var money = Money.Yen(6);

// define money implicit using currency of current culture/region
var money = new Money(6.54m);
Money money = 6.54m;
Money money = 6;
Money money = (Money)6.54; // need explict cast from double data type  

// auto-rounding to the minor unit will take place with MidpointRounding.ToEven
// also known as banker's rounding 
var euro = new Money(765.425m, "EUR"); // EUR 765.42
var euro = new Money(765.425m, "EUR", MidpointRounding.AwayFromZero); // EUR 765.43

// deconstruct money
var money = new Money(10m, "EUR");
var (amount, currency) = money;

Money operations

var euro10 = Money.Euro(10);
var euro20 = Money.Euro(20);
var dollar10 = Money.USDollar(10);

// add and substract
var euro30 = euro10 + euro20;
var euro10 = euro20 - euro10;
var m = euro10 + dollar10; // will throw exception!
euro10 += euro20;
euro10 -= euro20;

// compare money
euro10 == euro20; // false
euro10 != euro20; // true;
euro10 == dollar10; // false;
euro20 > euro10; // true;
euro10 <= dollar10; // will throw exception!

// decrement and increment by minor unit
var yen = new Money(765m, "JPY"); // the smallest unit is 1 yen
var euro = new Money(765.43m, "EUR");
++yen; // JPY 766
--yen; // JPY 765
++euro; // EUR 765.44
--euro; // EUR 765.43

Money formatting

var yen = new Money(765m, "JPY");
var euro = new Money(765.43m, "EUR");
var dollar = new Money(765.43m, "USD");
var dinar = new Money(765.432m, "BHD");

// Implicit when current culture is 'en-US'
yen.ToString();    // "¥765"
euro.ToString();   // "€765.43"
dollar.ToString(); // "$765.43"
dinar.ToString();  // "BD765.432"

yen.ToString("C2");    // "¥765.00"
euro.ToString("C2");   // "€765.43"
dollar.ToString("C2"); // "$765.43"
dinar.ToString("C2");  // "BD765.43"

// Implicit when current culture is 'nl-BE'
yen.ToString();    // "¥ 765"
euro.ToString();   // "€ 765,43"
dollar.ToString(); // "$ 765,43"
dinar.ToString();  // "BD 765,432"

// Implicit when current culture is 'fr-BE'
yen.ToString();    // "765 ¥"
euro.ToString();   // "765,43 €"
dollar.ToString(); // "765,43 $"
dinar.ToString();  // "765,432 BD"
}

// Explicit format for culture 'nl-NL'
var ci = new CultureInfo("nl-NL");

yen.ToString(ci);    // "¥ 765"
euro.ToString(ci);   // "€ 765,43"
dollar.ToString(ci); // "$ 765,43"
dinar.ToString(ci);  // "BD 765,432"

Money parsing

// Implicit parsing when current culture is 'nl-BE'
Money euro = Money.Parse("€ 765,43");
Money euro = Money.Parse("-€ 765,43");
Money euro = Money.Parse("€-765,43");
Money euro = Money.Parse("765,43 €");
Money yen = Money.Parse("¥ 765"); // throw FormatException, because ¥ symbol is used for Japanese yen and Chinese yuan
Money dollar = Money.Parse("$ 765,43"); // throw FormatException, because $ symbol is used for multiple currencies

// Implicit parsing when current culture is 'ja-JP'
Money yen = Money.Parse("¥ 765");

// Implicit parsing when current culture is 'zh-CN'
Money yuan = Money.Parse("¥ 765");

// Implicit parsing when current culture is 'en-US'
Money dollar = Money.Parse("$765.43");
Money dollar = Money.Parse("($765.43)"); // -$765.43

// Implicit parsing when current culture is 'es-AR'
Money peso = Money.Parse("$765.43");

// Explicit parsing when current culture is 'nl-BE'
Money euro = Money.Parse("€ 765,43", Currency.FromCode("EUR"));
Money euro = Money.Parse("765,43 €", Currency.FromCode("EUR"));
Money yen = Money.Parse("¥ 765", Currency.FromCode("JPY"));
Money yuan = Money.Parse("¥ 765", Currency.FromCode("CNY"));

// Implicit try parsing when current culture is 'nl-BE'
Money euro;
Money.TryParse("€ 765,43", out euro);

// Explicit try parsing when current culture is 'nl-BE'
Money euro;
Money.TryParse("€ 765,43", Currency.FromCode("EUR"), out euro);

Adding custom currencies

// Build custom currency
var builder = new CurrencyBuilder("BTC", "virtual")
				{
					EnglishName = "Bitcoin",
					Symbol = "฿",
                    ISONumber = "123", // iso number
					DecimalDigits = 8
				};

// Build, but will not register it
var bitcoin = builder.Build();
Money bitcoins = new Money(1.2, bitcoin);

// Build and register it for the life-time of the app domain in the namespace 'virtual'
var bitcoin = builder.Register();
Money bitcoins = new Money(1.2, "BTC"); // works if no overlap with other namespaces
Money bitcoins = new Money(1.2, Currency.FromCode("BTC", "virtual"));

// Replace ISO 4217 currency for the life-time of the app domain
Currency oldEuro = CurrencyBuilder.Unregister("EUR", "ISO-4217");

var builder = new CurrencyBuilder("EUR", "ISO-4217");
builder.LoadDataFromCurrency(oldEuro);
builder.EnglishName = "New Euro";
builder.DecimalDigits = 1;
builder.Register();

Currency newEuro = Currency.FromCode("EUR");
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].