'Declaration Public Operator +( _ ByVal left As TdDecimal, _ ByVal right As TdDecimal _ ) As TdDecimal
'Usage
Parameters
- left
- The operand that appears to the left of the '+' sign.
- right
- The operand that appears to the right of the '+' sign.
'Declaration Public Operator +( _ ByVal left As TdDecimal, _ ByVal right As TdDecimal _ ) As TdDecimal
'Usage
Exception | Description |
---|---|
System.OverflowException | The precision of the result exceeds the maximum precision (38) of a TdDecimal. The scale of an operand could not be adjusted to match the other operand's scale. |
If one of the parameter is TdDecimal.Null, the result will be TdDecimal.Null
.
There are two cases when an OverflowException will be thrown:
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.
When two number are added and the precision of the result will be greater than the MaxPrecision
an Overflow exception will be thrown.
// 1 + (-0.00000000000000000000000000000000000001) = 0.99999999999999999999999999999999999999 TdDecimal left01 = new TdDecimal(1, 0, 0, 0, 1, 0); // left01 = 1 TdDecimal right01 = new TdDecimal(unchecked((Int32)0xFFFFFFFF), unchecked((Int32)0xFFFFFFFF), unchecked((Int32)0xFFFFFFFF), unchecked((Int32)0xFFFFFFFF), 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 examples, an OverflowException will be thrown when adding the numbers // 99.357683940586721368475978471096874567 + 10 // An OverflowException is thrown because the result will have a precision greater than MaxPrecision. TdDecimal except01 = TdDecimal.Parse("99.357683940586721368475978471096874567") + TdDecimal.Parse("10"); // 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("100,445,234,554,774,908,493,123,496,675");
Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019