Struct SwiftAmt
A financial amount with currency.
Implements
Inherited Members
Namespace: Subsembly.Swift
Assembly: Subsembly.Sepa.dll
Syntax
public struct SwiftAmt : IComparable
Remarks
This struct also includes some static convenience methods for parsing and formatting decimal numbers according to SWIFT, HBCI and FinTS.
Constructors
SwiftAmt(decimal, string)
Constructs a SwiftAmt instance with the given properties.
Declaration
public SwiftAmt(decimal dcValue, string sCurrency)
Parameters
Type | Name | Description |
---|---|---|
decimal | dcValue | Decimal value in the range from minus MaxValue through plus MaxValue. |
string | sCurrency | The ISO currency code that denominates this amount. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The parameter sCurrency was |
ArgumentOutOfRangeException | The parameter sCurrency was not a string consisting of three upper case letters, or the dcValue was not in the allowed range. |
SwiftAmt(string, string)
Constructs a SwiftAmt instance from a decimal value given as a formatted string.
Declaration
public SwiftAmt(string sValue, string sCurrency)
Parameters
Type | Name | Description |
---|---|---|
string | sValue | |
string | sCurrency | The ISO currency code that denominates this amount. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The parameter sValue or sCurrency was |
ArgumentOutOfRangeException | The parameter sCurrency was not a string consisting of three upper case letters, or the given sValue was an empty string, or was longer than 15 characters. |
FormatException | The given sValue was not an acceptable representation according to the method Parse(string). |
Fields
MaxValue
The maximum value allowed for a monetary amount stored in a SwiftAmt instance.
Declaration
public const decimal MaxValue = 99999999999999
Field Value
Type | Description |
---|---|
decimal |
NullAmt
Represents a null amount.
Declaration
public static readonly SwiftAmt NullAmt
Field Value
Type | Description |
---|---|
SwiftAmt |
Properties
Currency
The ISO currency code that denominates this amount.
Declaration
public string Currency { get; set; }
Property Value
Type | Description |
---|---|
string | An ISO currency code consists of three upper case letters. Any other value is not allowed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | An attempt to set a null reference will cause an ArgumentNullException to be thrown. |
ArgumentOutOfRangeException | An attempt to set the currency code to a string that does not contain three upper case letters will cause an ArgumentOutOfRangeException to be thrown. |
IsNegative
Indicates whether the Value is less than zero.
Declaration
public bool IsNegative { get; }
Property Value
Type | Description |
---|---|
bool |
IsNull
Indicates whether this SwiftAmt instance is logically null.
Declaration
public bool IsNull { get; }
Property Value
Type | Description |
---|---|
bool |
Value
The numerical value of this amount.
Declaration
public decimal Value { get; set; }
Property Value
Type | Description |
---|---|
decimal | Decimal value in the range from minus MaxValue through plus MaxValue. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | An attempt to set a value smaller than minus MaxValue, or a value greater than plus MaxValue will cause an ArgumentOutOfRangeException to be thrown. |
Methods
Add(decimal)
Returns a new SwiftAmt with the sum of the Value and
the given signed dcValue
and the same Currency.
Declaration
public SwiftAmt Add(decimal dcValue)
Parameters
Type | Name | Description |
---|---|---|
decimal | dcValue |
Returns
Type | Description |
---|---|
SwiftAmt |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The sum of Value and |
CompareTo(object)
Declaration
public int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
int |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj |
Returns
Type | Description |
---|---|
bool |
Overrides
Format(decimal)
Formats a decimal value into a string of characters using a comma as the decimal point symbol and generating no trailing zeroes.
Declaration
public static string Format(decimal dcValue)
Parameters
Type | Name | Description |
---|---|---|
decimal | dcValue | Decimal value in the range from decimal zero through MaxValue that shall be formatted. |
Returns
Type | Description |
---|---|
string | String that contains a formatted representation of the given decimal value. The returned string contains at most 15 chracters. |
Remarks
This is an overloaded convenience method that internally just calls Format(decimal, char, int) passing a comma as the decimal point symbol and -1 as the desired number of decimal places.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The dcValue was negative or greater than MaxValue. |
FormatException | If the given decimal value has more than 13 significant decimal places , or if the resulting representation would have more than 15 characters, then a FormatException is thrown. |
Format(decimal, char, int)
Formats a decimal value into a string of characters.
Declaration
public static string Format(decimal dcValue, char chDecimalPoint, int nDecimalPlaces)
Parameters
Type | Name | Description |
---|---|---|
decimal | dcValue | Decimal value up to MaxValue that shall be formatted. If this is a negative value, then a minus sign will be prefixed. |
char | chDecimalPoint | Character to be used as the decimal point symbol. Currently this must be either '.' or ',', any other value is not allowed. For SWIFT, HBCI and FinTS decimal values, the decimal point must be a comma ','. For XML representations, including the FinTS XML representation, the decimal point must be a full stop '.'. |
int | nDecimalPlaces | The desired number of decimal places following the decimal point. The formatted string will be filled up with trailing zeroes to that number of decimal places. Note that trailing zeroes are not allowed in HBCI and FinTS representations of decimal numbers. If this parameter is -1, then the formatted string will include whatever number of decimal places it takes to represent the given decimal value. In this case there will never be any trailing zeroes. The maximum allowed value for this parameter is 13. A value of 13 would imply, that there can be at most one digit in front of the decimal point. |
Returns
Type | Description |
---|---|
string | String that contains a formatted representation of the given decimal value. The returned string contains at most 15 chracters. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If any of the given parameters is outside the defined range, then an ArgumentOutOfRangeException is thrown. |
FormatException | If the given decimal value has more significant decimal places than specified in nDecimalPlaces, or if the resulting representation would have more than 15 characters, then a FormatException is thrown. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
Parse(string)
Parses a string representation of a decimal number into a Decimal
value.
Declaration
public static decimal Parse(string sValue)
Parameters
Type | Name | Description |
---|---|---|
string | sValue | String representation of a decimal number that shall be parsed. |
Returns
Type | Description |
---|---|
decimal | The parsed decimal value. |
Remarks
Any white space leading, trailing, or inside the value string is ignored.
If the string sValue
is null, empty or all whitespace, then
this method returns the value zero.
The string may contain a leading plus '+' or minus '-' sign. If there is a leading minus sign, then the return value will be negative, unless it is zero anyway.
The string may use a decimal point and thousands group separators. However, only the characters comma ',' and full stop '.' are accepted for these. The last ',' or '.' in the string is assumed to be the decimal point.
Any leading or trailing zeroes are ignored.
Here are some valid and some invalid examples:
0.01 | This is just one of the many possible valid representations of that value. All the following representations would also be accepted, and lead to the very same value: "0,01", "0,0100", "0000.0100". |
99999999999999, | This is the maxium value that can be parsed by this method. Any higher value will cause a FormatException to be thrown. Alternative acceptable representations of this value are: "99999999999999", "99999999999999.", "99,999,999,999,999.00", "99.999.999.999.999,00", "0000099999999999999". |
0,0000000000001 | This is the smallest value (apart from zero) that can be parsed by this method. Alternative acceptable representations of this value are: "0.0000000000001", ",0000000000001". |
123 234, 00 | Interior white space is ignored, hence this is a valid representation. |
-123, | This is a valid representation of a negative value. Also valid are: " - 123,00", "- 123.", "-0123". |
Exceptions
Type | Condition |
---|---|
FormatException | The given |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
TryParse(string)
Tries to parse the string with any number of decimal places.
Declaration
public static decimal TryParse(string sValue)
Parameters
Type | Name | Description |
---|---|---|
string | sValue |
Returns
Type | Description |
---|---|
decimal | If the string was successfully parsed, then its decimal value is returned. If the string cannot be parsed successfully, then zero is returned. |
Remarks
Internally this calls Parse(string), wrapped by a try/catch block.
Operators
operator ==(SwiftAmt, SwiftAmt)
Declaration
public static bool operator ==(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |
operator >(SwiftAmt, SwiftAmt)
Declaration
public static bool operator >(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |
operator >=(SwiftAmt, SwiftAmt)
Declaration
public static bool operator >=(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |
operator !=(SwiftAmt, SwiftAmt)
Declaration
public static bool operator !=(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |
operator <(SwiftAmt, SwiftAmt)
Declaration
public static bool operator <(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |
operator <=(SwiftAmt, SwiftAmt)
Declaration
public static bool operator <=(SwiftAmt lhs, SwiftAmt rhs)
Parameters
Type | Name | Description |
---|---|---|
SwiftAmt | lhs | |
SwiftAmt | rhs |
Returns
Type | Description |
---|---|
bool |