Send feedback on this topic.
Teradata.Client.Provider
Subtraction Operator (TdDecimal)
Example 



Teradata.Client.Provider Namespace > TdDecimal Structure : Subtraction Operator
The operand that appears to the left of the '-' sign.
The operand that appears to the right of the '-' sign.
Calculates the result of subtracting two TdDecimal operands.
Syntax
'Declaration
 
Public Operator -( _
   ByVal left As TdDecimal, _
   ByVal right As TdDecimal _
) As TdDecimal
'Usage
 
public TdDecimal operator -( 
   TdDecimal left,
   TdDecimal right
)
public:
TdDecimal operator -( 
   TdDecimal left,
   TdDecimal right
)

Parameters

left
The operand that appears to the left of the '-' sign.
right
The operand that appears to the right of the '-' sign.

Return Value

A TdDecimal containing the result
Exceptions
ExceptionDescription
The scale of an operand could not be adjusted to match the other operand's scale.
Remarks

If one of the parameter is TdDecimal.Null, the result will be TdDecimal.Null.

When two numbers with different scales are added, an attempt is made to adjust the scale of one of the operands so that the scale of both operands are the same. The operand that has the least scale is always adjusted upward to match the operand that has the greatest scale. When adjusting the operand, a check is done to make sure that the new precision will not be greater than the TdDecimal.MaxPrecision. If this occurs an OverflowException will be thrown.

Example
The following example creates pairs of TdDecimals and subtracts them using the - operator.
// 1 - 0.00000000000000000000000000000000000001 = 0.99999999999999999999999999999999999999
TdDecimal left01 = new TdDecimal(1, 0, 0, 0, 1, 0);      // left01 = 1
TdDecimal right01 = new TdDecimal(1, 0, 0, 0, 38, 38);   // right01 = 0.00000000000000000000000000000000000001
TdDecimal result01 = left01 - right01;
Console.WriteLine("{0} - {1} = {2}", left01, right01, result01);
 
// 3.4538475968734 - 0.4538475968734 = 3
TdDecimal left02 = TdDecimal.Parse("3.4538475968734");
TdDecimal right02 = TdDecimal.Parse("0.4538475968734");
TdDecimal result02 = left02 + right02;
Console.WriteLine("{0} - {1} = {2}", left02, right02, result02);
 
// In the following example, an OverflowException will be thrown when subtracting the numbers
 
// 15.98798734398453 - 100,445,234,554,774,908,493,123,496,675
// An OverflowException is thrown because when the scale of the right operand is adjusted to
// match the scale of the left operand, the precision of the right will be greater than the MaxPrecision
TdDecimal except02 = TdDecimal.Parse("15.98798734398453") + TdDecimal.Parse("100445234554774908493123496675");
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdDecimal Structure
TdDecimal Members