Struct Money
- Namespace
- ATAS.DataFeedsCore
- Assembly
- ATAS.DataFeedsCore.dll
Represents decimal amount in some currency
public readonly struct Money
- Extension Methods
Constructors
Money()
Not supported: a money value needs a currency.
public Money()
Exceptions
- InvalidOperationException
Always.
Money(decimal, CurrencyInfo)
Creates an amount in a currency.
public Money(decimal value, CurrencyInfo currency)
Parameters
valuedecimalThe amount.
currencyCurrencyInfoCurrency of the amount.
Exceptions
- ArgumentNullException
The currency code is null, empty or white space.
Properties
Currency
public string Currency { get; }
Property Value
- string
CurrencyInfo
Currency of the amount with its display precision.
public CurrencyInfo CurrencyInfo { get; }
Property Value
Value
The amount.
public decimal Value { get; init; }
Property Value
- decimal
Methods
ToString()
Formats the amount with DisplayFormat in the current UI culture, followed by the currency code.
public override string ToString()
Returns
- string
A string such as
"1,234.50 USD", or"Invalid money"when there is no currency.
ToString(string?, IFormatProvider?)
Formats the amount using a money format template.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringTemplate in which
vstands for the amount (optionally followed by:and a numeric format),cfor the currency code and</code> escapes the next character; null meansv. The amount uses DisplayFormat when the template gives no numeric format.formatProviderIFormatProviderCulture-specific formatting information.
Returns
- string
The formatted amount.
Operators
operator +(Money, Money)
Adds two amounts of the same currency.
public static Money operator +(Money m1, Money m2)
Parameters
Returns
- Money
The sum in the currency of
m1.
Exceptions
- InvalidOperationException
A currency is missing or the currencies differ.
operator +(Money, decimal)
Adds a plain number to the amount.
public static Money operator +(Money m1, decimal m2)
Parameters
m1MoneyThe value.
m2decimalNumber to add, in the currency of
m1.
Returns
- Money
The sum in the currency of
m1.
operator /(Money, decimal)
Divides the amount by a number.
public static Money operator /(Money m1, decimal m2)
Parameters
m1MoneyThe value.
m2decimalThe divisor.
Returns
- Money
The quotient in the currency of
m1.
Exceptions
- DivideByZeroException
m2is 0.
implicit operator decimal(Money)
Returns the amount without the currency.
public static implicit operator decimal(Money m)
Parameters
mMoneyThe value.
Returns
- decimal
operator *(Money, decimal)
Multiplies the amount by a number.
public static Money operator *(Money m1, decimal m2)
Parameters
m1MoneyThe value.
m2decimalThe multiplier.
Returns
- Money
The product in the currency of
m1.
operator -(Money, Money)
Subtracts an amount of the same currency.
public static Money operator -(Money m1, Money m2)
Parameters
Returns
- Money
The difference in the currency of
m1.
Exceptions
- InvalidOperationException
A currency is missing or the currencies differ.
operator -(Money, decimal)
Subtracts a plain number from the amount.
public static Money operator -(Money m1, decimal m2)
Parameters
m1MoneyThe value.
m2decimalNumber to subtract, in the currency of
m1.
Returns
- Money
The difference in the currency of
m1.
operator -(Money)
Negates the amount.
public static Money operator -(Money m1)
Parameters
m1MoneyThe value.
Returns
- Money
The value with the opposite sign in the same currency.