Table of Contents

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

value decimal

The amount.

currency CurrencyInfo

Currency of the amount.

Exceptions

ArgumentNullException

The currency code is null, empty or white space.

Properties

Currency

Currency code; null for a default instance.

public string Currency { get; }

Property Value

string

CurrencyInfo

Currency of the amount with its display precision.

public CurrencyInfo CurrencyInfo { get; }

Property Value

CurrencyInfo

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

format string

Template in which v stands for the amount (optionally followed by : and a numeric format), c for the currency code and </code> escapes the next character; null means v. The amount uses DisplayFormat when the template gives no numeric format.

formatProvider IFormatProvider

Culture-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

m1 Money

First value.

m2 Money

Second value.

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

m1 Money

The value.

m2 decimal

Number 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

m1 Money

The value.

m2 decimal

The divisor.

Returns

Money

The quotient in the currency of m1.

Exceptions

DivideByZeroException

m2 is 0.

implicit operator decimal(Money)

Returns the amount without the currency.

public static implicit operator decimal(Money m)

Parameters

m Money

The value.

Returns

decimal

operator *(Money, decimal)

Multiplies the amount by a number.

public static Money operator *(Money m1, decimal m2)

Parameters

m1 Money

The value.

m2 decimal

The 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

m1 Money

The value to subtract from.

m2 Money

The value to subtract.

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

m1 Money

The value.

m2 decimal

Number 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

m1 Money

The value.

Returns

Money

The value with the opposite sign in the same currency.