ICurrency Interface
Definition
- Namespace
- Bodu.Financial.Currencies
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.0.0
- Source
- ICurrency.cs
Identifies a currency at the type-system level, supplying the ISO 4217 code, minor-unit precision, and optional cash-rounding and historicity metadata used by Money<TCurrency>.
public interface ICurrency
Remarks
Implementations of ICurrency are tag types - they exist solely to parameterize Money<TCurrency> and carry the currency's static metadata. They are never instantiated; the shipped implementations declare a private constructor and expose only static members.
The interface relies on the C# 11 static-abstract-member feature, so members are accessed through the type itself (
USD.IsoCode, USD.MinorUnits) and via TCurrency.IsoCode from within generic code constrained by
where TCurrency : ICurrency.
IsoCode and MinorUnits are required. The remaining members (
CashRoundingIncrement, IsHistoric, DemonetizedOn,
SuccessorIsoCode) are static virtual with sensible defaults so existing custom implementations
remain source-compatible - only the shipped Bodu.Financial.Currencies tags override the defaults to surface
country-specific cash rounding or historic-currency metadata.
using Bodu.Financial;
using Bodu.Financial.Currencies;
// Metadata is read statically from the tag type - no instance is ever created.
string code = USD.IsoCode; // "USD"
int minorUnits = USD.MinorUnits; // 2
int numeric = USD.NumericCode; // 840
// The same members are reachable through a generic constraint.
static string DescribeCurrency<TCurrency>() where TCurrency : ICurrency =>
$"{TCurrency.IsoCode} ({TCurrency.MinorUnits} minor units)";
Properties
CashRoundingIncrement
Gets the smallest cash denomination of the currency, expressed in the major unit.
public static decimal CashRoundingIncrement { get; }
Property Value
- decimal
The cash-rounding increment in the major unit (for example,
0.05mfor CHF's five-rappen smallest circulating coin,0.05mfor AUD / CAD cash totals since smallest coins were withdrawn, or1mfor SEK / NOK / ISK), or0mwhen the currency does not require special cash rounding beyond its MinorUnits precision.
Remarks
The default of 0m is interpreted by RoundToCash(MidpointRounding) as "no
special cash rounding required", so the rounding becomes a no-op. Cash-rounding rules apply only to physical
cash totals; electronic transactions retain the full MinorUnits precision.
DemonetizedOn
Gets the date the currency was withdrawn from circulation, if known.
public static DateOnly? DemonetizedOn { get; }
Property Value
EnglishName
Gets the English-language name of the currency.
public static string EnglishName { get; }
Property Value
- string
The currency's name in English, in singular form and Title Case (for example,
"United States Dollar","Euro", or"Australian Dollar"), or an empty string when no name is supplied.
Remarks
The English name is used by Money<TCurrency> formatting in the L specifier path (
"1,234.56 Australian Dollar") and is available through EnglishName on the
runtime-tagged registry entry. The default is the empty string so existing ICurrency
implementations remain source-compatible; when empty, the L specifier falls back to the ISO-substitution
form rather than emitting a trailing space with no name.
IsHistoric
Gets a value indicating whether the currency has been demonetized and is no longer in active circulation.
public static bool IsHistoric { get; }
Property Value
- bool
true when the currency is a historic predecessor (for example, the Euro-zone national currencies replaced in 2002, or
ZWLsince its 2024 demonetization); otherwise false.
Remarks
Historic currencies still participate fully in arithmetic and formatting so consumers can process legacy data; IsHistoric exists for filtering and reporting only.
IsoCode
Gets the ISO 4217 three-letter alphabetic code that identifies the currency.
public static abstract string IsoCode { get; }
Property Value
- string
An uppercase three-letter currency code, such as
"USD","EUR", or"JPY".
MinorUnits
Gets the number of fractional digits in the currency's minor unit - the precision Money<TCurrency> rounds to on construction and formats by default.
public static abstract int MinorUnits { get; }
Property Value
- int
The non-negative number of decimal places the currency uses; typically two (for
USD,EUR, etc.), zero (forJPY,KRW,CLP), or three (forBHD,KWD,OMR).
NumericCode
Gets the ISO 4217 three-digit numeric code that identifies the currency.
public static int NumericCode { get; }
Property Value
- int
The three-digit numeric code (for example,
840forUSD,36forAUD,392forJPY), or0when the currency is custom or the numeric code is unknown.
Remarks
The numeric code is the second public identifier defined by ISO 4217 and is widely used by payment formats
(SWIFT MT messages, ISO 20022). The default of 0 keeps existing custom ICurrency
implementations source-compatible; the shipped Bodu.Financial.Currencies tags override it with the
canonical ISO numeric value.
SuccessorIsoCode
Gets the ISO 4217 alphabetic code of the currency that replaced this one, when applicable.
public static string? SuccessorIsoCode { get; }
Property Value
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |