NMoney 4.0.0

dotnet add package NMoney --version 4.0.0                
NuGet\Install-Package NMoney -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NMoney" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NMoney --version 4.0.0                
#r "nuget: NMoney, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NMoney as a Cake Addin
#addin nuget:?package=NMoney&version=4.0.0

// Install NMoney as a Cake Tool
#tool nuget:?package=NMoney&version=4.0.0                

Money

Value-type contains the amount of money in decimal and a link to an instance of currency.

ICurrency

An instance of this interface must contain:

  • Name of the currency,
  • Currency code (e.g. in ISO 4217),
  • Number of characters minor currency (eg cents, a penny ...)
  • Symbol of currency sign

ICurrencySet

Customizable currency collection

NuGet Version NuGet Downloads

Usage

Initializing money

var eur15 = new Money(15m, Iso4217.CurrencySet.EUR);
var usd10 = Iso4217.CurrencySet.USD.Money(10m);
var zero = Money.Zero;

Money operations

var usd10 = Iso4217.CurrencySet.USD.Money(10m);
var usd15 = Iso4217.CurrencySet.USD.Money(15m);
var eur1 = Iso4217.CurrencySet.USD.Money(1m);
var eur10 = Iso4217.CurrencySet.USD.Money(10m);
var eur123 = Iso4217.CurrencySet.USD.Money(123m);

// add and substract
var usd25 = usd10 + usd15;
var eur122 = eur123 - eur1;
var wtf = usd10 + eur1; // will throw exception

var usd10 = Money.Zero + usd10;
var usdSum = default(Money); // Money.Zero - default value of this struct
usdSum += usd10;
usdSum += usd15; // now usdSum contain 25 dollars

// multiply and division by constant
var usd5 = usd15 / 3;
var eur15 = eur1 * 15;

// compare money
usd10 == eur10; // false
usd10 != eur10; // true;
eur10 == eur1 * 10; // true
usd15 > usd10; // true;
usd15 <= eur10; // will throw exception

// rounding
Iso4217.CurrencySet.USD.Money(20.953m).CeilingMajorUnit() // 21 USD
Iso4217.CurrencySet.USD.Money(20.953m).FloorMajorUnit()   // 20 USD
Iso4217.CurrencySet.USD.Money(20.953m).CeilingMinorUnit() // 20.96 USD
Iso4217.CurrencySet.USD.Money(20.953m).FloorMinorUnit()   // 20.95 USD

Serializing

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NMoney:

Package Downloads
NMoney.Bson

Bson serialization and MongoDB query rendering for NMoney

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 1,734 2/18/2024
3.1.0 7,953 11/29/2020
3.0.0 7,721 11/5/2018
2.0.0 1,235 10/13/2017