ThomasJaeger / TeixeiraSoftware.Finance.Currency

A simple cross-platform currency class library

Home Page:https://andremarcondesteixeira.github.io/TeixeiraSoftware.Finance.Currency/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TeixeiraSoftware.Finance.Currency

TeixeiraSoftware.Finance.Currency

Build status license Pull Requests NuGet BCH compliance

A simple cross platform currency class library for .Net, that follows the ISO 4217 standard.

The implementation of this library is compatible with .Net Standard 2.0 (see https://docs.microsoft.com/en-us/dotnet/standard/net-standard for details).

This package depends on TeixeiraSoftware.Finance.ICurrency.

Usage

You can get a currency instance by three different ways:

  • Calling a factory property, where XXX is the three letters ISO code of the currency:
var currency = Currency.XXX;
  • Using the ByAlphabeticCode method, where, again, XXX is the three letters ISO code of the currency:
var currency = Currency.ByAlphabeticCode("XXX");
  • Using the ByNumericCode method, where 999 is the three numbers ISO code of the currency:
// Note that the numeric code is a string
var currency = Currency.ByNumericCode("999");

Properties

The Currency struct have five read only properties:

public partial struct Currency : ICurrency, IComparable, IComparable<ICurrency>
{
    // The alphabetic ISO code of the currency
    // This property is always the same as AlphabeticCode
    public string Symbol { get; }

    // The name of the currency
    public string Name { get; }

    // The alphabetic ISO code of the currency
    // This property is always the same as Symbol
    public string AlphabeticCode {
        get {
            return Symbol;
        }
    }

    // The ISO numeric code of the currency
    public string NumericCode { get; }

    // The minor units of the currency
    public byte MinorUnits { get; }
}

Comparing currencies

The available comparison operators are == and !=. The .Equals method is also available.

// returns true
var areCurrenciesEquivalent = (Currency.XXX == Currency.XXX);

// returns false
var areCurrenciesEquivalent = (Currency.XXX != Currency.XXX);

Listing all the currencies

You can use the Currency.AllCurrencies property to get a list of all the currencies:

var allCurrencies = Currency.AllCurrencies;

foreach (var currency in allCurrencies)
{
    var currencyName = currency.Name;
    var currencyISOAlphabeticCode = currency.AlphabeticCode;
    var currencyISONumericCode = currency.NumericCode;
    var currencyMinorUnits = currency.MinorUnits;
}

Contributing

You can see some topics that you can help with in the issues section of the project. You can also contribute by doing unit tests, writing documentation, making pull requests or sharing the project.

About

A simple cross-platform currency class library

https://andremarcondesteixeira.github.io/TeixeiraSoftware.Finance.Currency/

License:MIT License


Languages

Language:C# 100.0%