Struct SwiftAmt

Namespace
Subsembly.Swift
Assembly
Subsembly.Sepa.dll

A financial amount with currency.

public struct SwiftAmt : IComparable
Implements
Inherited Members

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.

public SwiftAmt(decimal dcValue, string sCurrency)

Parameters

dcValue decimal

Decimal value in the range from minus MaxValue through plus MaxValue.

sCurrency string

The ISO currency code that denominates this amount.

Exceptions

ArgumentNullException

The parameter sCurrency was null.

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.

public SwiftAmt(string sValue, string sCurrency)

Parameters

sValue string
sCurrency string

The ISO currency code that denominates this amount.

Exceptions

ArgumentNullException

The parameter sValue or sCurrency was null.

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.

public const decimal MaxValue = 99999999999999

Field Value

decimal

NullAmt

Represents a null amount.

public static readonly SwiftAmt NullAmt

Field Value

SwiftAmt

Properties

Currency

The ISO currency code that denominates this amount.

public string Currency { get; set; }

Property Value

string

An ISO currency code consists of three upper case letters. Any other value is not allowed.

Exceptions

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.

public bool IsNegative { get; }

Property Value

bool

IsNull

Indicates whether this SwiftAmt instance is logically null.

public bool IsNull { get; }

Property Value

bool

Value

The numerical value of this amount.

public decimal Value { get; set; }

Property Value

decimal

Decimal value in the range from minus MaxValue through plus MaxValue.

Exceptions

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.

public SwiftAmt Add(decimal dcValue)

Parameters

dcValue decimal

Returns

SwiftAmt

Exceptions

ArgumentOutOfRangeException

The sum of Value and dcValue is smaller than minus MaxValue, or greater than plus MaxValue.

CompareTo(object)

public int CompareTo(object obj)

Parameters

obj object

Returns

int

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Format(decimal)

Formats a decimal value into a string of characters using a comma as the decimal point symbol and generating no trailing zeroes.

public static string Format(decimal dcValue)

Parameters

dcValue decimal

Decimal value in the range from decimal zero through MaxValue that shall be formatted.

Returns

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

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.

public static string Format(decimal dcValue, char chDecimalPoint, int nDecimalPlaces)

Parameters

dcValue decimal

Decimal value up to MaxValue that shall be formatted. If this is a negative value, then a minus sign will be prefixed.

chDecimalPoint char

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 '.'.

nDecimalPlaces int

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

string

String that contains a formatted representation of the given decimal value. The returned string contains at most 15 chracters.

Exceptions

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()

public override int GetHashCode()

Returns

int

Parse(string)

Parses a string representation of a decimal number into a Decimal value.

public static decimal Parse(string sValue)

Parameters

sValue string

String representation of a decimal number that shall be parsed.

Returns

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

FormatException

The given sValue was not an acceptable representation according to the rules of this method.

ToString()

public override string ToString()

Returns

string

TryParse(string)

Tries to parse the string with any number of decimal places.

public static decimal TryParse(string sValue)

Parameters

sValue string

Returns

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)

public static bool operator ==(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool

operator >(SwiftAmt, SwiftAmt)

public static bool operator >(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool

operator >=(SwiftAmt, SwiftAmt)

public static bool operator >=(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool

operator !=(SwiftAmt, SwiftAmt)

public static bool operator !=(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool

operator <(SwiftAmt, SwiftAmt)

public static bool operator <(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool

operator <=(SwiftAmt, SwiftAmt)

public static bool operator <=(SwiftAmt lhs, SwiftAmt rhs)

Parameters

lhs SwiftAmt
rhs SwiftAmt

Returns

bool