Struct MonetaryValue
Represents a monetary amount in a specific currency.
Implements
Namespace: Singulink.Globalization
Assembly: Singulink.Globalization.Currency.dll
Syntax
public readonly struct MonetaryValue : IComparable<MonetaryValue>, IEquatable<MonetaryValue>, ISpanFormattable, IFormattable, IAdditionOperators<MonetaryValue, MonetaryValue, MonetaryValue>, IAdditionOperators<MonetaryValue, decimal, MonetaryValue>, IComparisonOperators<MonetaryValue, MonetaryValue, bool>, IEqualityOperators<MonetaryValue, MonetaryValue, bool>, IDecrementOperators<MonetaryValue>, IDivisionOperators<MonetaryValue, decimal, MonetaryValue>, IDivisionOperators<MonetaryValue, MonetaryValue, decimal>, IIncrementOperators<MonetaryValue>, IMultiplyOperators<MonetaryValue, decimal, MonetaryValue>, ISubtractionOperators<MonetaryValue, MonetaryValue, MonetaryValue>, ISubtractionOperators<MonetaryValue, decimal, MonetaryValue>, IUnaryNegationOperators<MonetaryValue, MonetaryValue>, IUnaryPlusOperators<MonetaryValue, MonetaryValue>, ISpanParsable<MonetaryValue>, IParsable<MonetaryValue>
Constructors
| Name | Description |
|---|---|
| MonetaryValue(decimal, Currency) | Initializes a new instance of the MonetaryValue struct with the specified amount and currency. |
| MonetaryValue(decimal, string) | Initializes a new instance of the MonetaryValue struct with the specified amount and currency code from the Default currency registry. |
Properties
| Name | Description |
|---|---|
| Amount | Gets the amount this value represents in its currency. |
| Currency | Gets the currency associated with this value. |
| CurrencyOrDefault | Gets the currency associated with this value or null if this is a default monetary value with no currency associated with it. |
| Default | Gets the default MonetaryValue value, which is not associated with any currency and has a zero amount. |
| IsDefault | Gets a value indicating whether this is a default value. Default values have a |
Methods
| Name | Description |
|---|---|
| Abs() | Returns a value with the absolute value of this value's amount in the same currency. |
| Allocate(int) | Allocates this value into the specified number of equal parts that are valid amounts under the currency's RoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| Allocate(int, RoundingPolicy) | Allocates this value into the specified number of equal parts that are valid amounts under the specified rounding policy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| Allocate(params ReadOnlySpan<decimal>) | Allocates this value into parts proportional to the specified ratios that are valid amounts under the currency's RoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| Allocate(ReadOnlySpan<decimal>, RoundingPolicy) | Allocates this value into parts proportional to the specified ratios that are valid amounts under the specified rounding policy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| AllocateToCash(int) | Allocates this value into the specified number of equal parts that are valid cash amounts under the currency's CashRoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| AllocateToCash(params ReadOnlySpan<decimal>) | Allocates this value into parts proportional to the specified ratios that are valid cash amounts under the currency's CashRoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy. |
| CompareTo(MonetaryValue) | Compares this value to the specified value. Values in different currencies are ordered by their currencies first. |
| Create(decimal, Currency) | Creates a new MonetaryValue value with the specified amount and currency. |
| Create(decimal, string) | Creates a new MonetaryValue value with the specified amount and currency code from the Default currency registry. |
| CreateOrDefault(decimal, Currency?) | Creates a new MonetaryValue value with the specified amount and currency. Allows creating default monetary values by passing |
| CreateOrDefault(decimal, string?) | Creates a new MonetaryValue value with the specified amount and currency code from the Default currency registry.
Allows creating default monetary values by passing |
| Equals(MonetaryValue) | Determines whether this value is equal to the specified value. |
| Equals(MonetaryValue, MonetaryValue) | Determines whether the two specified values are equal. |
| Equals(object?) | Determines whether this value is equal to the specified object. |
| GetHashCode() | Gets the hash code for this value. |
| Max(MonetaryValue, MonetaryValue) | Returns the larger of two monetary values. |
| Min(MonetaryValue, MonetaryValue) | Returns the smaller of two monetary values. |
| Parse(ReadOnlySpan<char>, MonetaryStyles, IFormatProvider?) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| Parse(ReadOnlySpan<char>, IFormatProvider?) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| Parse(string, MonetaryStyles, IFormatProvider?) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| Parse(string, IFormatProvider?) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| Round(MidpointRounding) | Returns a value rounded according to the currency's RoundingPolicy using the specified midpoint rounding mode (which defaults to ToEven "banker's rounding"). |
| RoundToCash(MidpointRounding) | Returns a value rounded according to the currency's CashRoundingPolicy using the specified midpoint rounding mode (which defaults to ToEven "banker's rounding"). |
| ToDefaultIfZero() | Returns Default if this value's Amount is |
| ToString() | Returns a culture-dependent international string representation of this value's currency and amount. |
| ToString(string?, IFormatProvider?) | Returns a string representation of this value's currency and amount. |
| TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?) | Formats this value's currency and amount into a span of characters. |
| TryParse(ReadOnlySpan<char>, MonetaryStyles, IFormatProvider?, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| TryParse(ReadOnlySpan<char>, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| TryParse(ReadOnlySpan<char>, IFormatProvider?, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| TryParse(string?, MonetaryStyles, IFormatProvider?, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| TryParse(string?, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
| TryParse(string?, IFormatProvider?, out MonetaryValue) | Converts the string representation of a monetary value to its MonetaryValue equivalent using the Default currency registry. |
Operators
| Name | Description |
|---|---|
| operator +(MonetaryValue, MonetaryValue) | Adds two values together to compute their sum. |
| operator +(MonetaryValue, decimal) | Adds two values together to compute their sum. |
| operator --(MonetaryValue) | Decrements a value. |
| operator /(MonetaryValue, MonetaryValue) | Divides one value by another to compute their quotient. |
| operator /(MonetaryValue, decimal) | Divides one value by another to compute their quotient. |
| operator ==(MonetaryValue, MonetaryValue) | Compares two values to determine equality. |
| operator >(MonetaryValue, MonetaryValue) | Compares two values to determine which is greater. |
| operator >=(MonetaryValue, MonetaryValue) | Compares two values to determine which is greater or equal. |
| operator ++(MonetaryValue) | Increments a value. |
| operator !=(MonetaryValue, MonetaryValue) | Compares two values to determine inequality. |
| operator <(MonetaryValue, MonetaryValue) | Compares two values to determine which is less. |
| operator <=(MonetaryValue, MonetaryValue) | Compares two values to determine which is less or equal. |
| operator *(MonetaryValue, decimal) | Multiplies two values together to compute their product. |
| operator -(MonetaryValue, MonetaryValue) | Subtracts two values to compute their difference. |
| operator -(MonetaryValue, decimal) | Subtracts two values to compute their difference. |
| operator -(MonetaryValue) | Computes the unary negation of a value. |
| operator +(MonetaryValue) | Computes the unary plus of a value. |