Monetary 2.0.0
dotnet add package Monetary --version 2.0.0
NuGet\Install-Package Monetary -Version 2.0.0
<PackageReference Include="Monetary" Version="2.0.0" />
<PackageVersion Include="Monetary" Version="2.0.0" />
<PackageReference Include="Monetary" />
paket add Monetary --version 2.0.0
#r "nuget: Monetary, 2.0.0"
#:package Monetary@2.0.0
#addin nuget:?package=Monetary&version=2.0.0
#tool nuget:?package=Monetary&version=2.0.0
Monetary
Monetary is a .NET library to make working with money safer and easier, designed to make currency, precision, and domain intent explicit in financial code. It is based on Martin Fowler's Money Pattern.
"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin
Problem
Primitive numeric types make money deceptively easy to represent and dangerously easy to misuse.
Using raw decimal, double, or float values throughout an application can
lead to code that:
- mixes values from different currencies without validation
- loses the domain meaning behind an amount
- scatters rounding, formatting, and precision rules across the codebase
- treats financial operations like ordinary arithmetic
- makes business rules harder to read, test, and audit
Money is not just a number. It is an amount in a currency, governed by business rules.
Approach
Monetary models money as a value object with currency awareness and clear operations. Instead of passing primitive amounts around, financial code can work with explicit domain concepts.
The goal is to make business logic read closer to the language of the domain:
var usd = Currencies.FromCurrencyCode("USD");
var eur = Currencies.FromCurrencyCode("EUR");
var pair = new CurrencyPair(usd!, eur!);
Currency-sensitive operations should be safe by default:
// Throws because an exchange pair must contain two different currencies.
var invalid = new CurrencyPair(Currencies.USD, Currencies.USD);
Design Goals
- Represent money as an immutable value object.
- Keep currency attached to every monetary amount.
- Prevent accidental arithmetic across different currencies.
- Centralize precision, rounding, and formatting behavior.
- Provide predefined ISO-style currency metadata.
- Provide APIs that make financial intent clear in application code.
- Support domain-first business logic without leaking primitive money rules everywhere.
Building
From the repository root:
dotnet build src/Monetary/Monetary.csproj
Usage
Until the first rebuilt package is published, reference the project directly from another .NET project:
dotnet add reference path/to/Monetary/src/Monetary/Monetary.csproj
Package installation instructions will be added when a stable release is available.
Why This Exists
Financial code should make invalid states difficult to express. Monetary exists to replace scattered primitive money handling with small, explicit, testable domain objects that carry the rules of money with them.
License
This project is licensed under the terms included in the repository license file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.