This documentation is archived and is not being maintained.
Decimal::Addition Operator
Visual Studio 2010
Adds two specified Decimal values.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- d1
- Type: System::Decimal
The first value to add.
- d2
- Type: System::Decimal
The second value to add.
| Exception | Condition |
|---|---|
| OverflowException | The return value is less than MinValue or greater than MaxValue. |
The following code example creates several pairs of Decimal values and calculates their sums with the Addition operator.
// Example of the Decimal addition and subtraction operators. using namespace System; // Display Decimal parameters and their sum and difference. void ShowDecimalSumDiff( Decimal Left, Decimal Right ) { String^ dataFmt = " {0,-18}{1,31}"; Console::WriteLine(); Console::WriteLine( dataFmt, "Decimal Left", Left ); Console::WriteLine( dataFmt, "Decimal Right", Right ); Console::WriteLine( dataFmt, "Left + Right", Left + Right ); Console::WriteLine( dataFmt, "Left - Right", Left - Right ); } int main() { Console::WriteLine( "This example of the Decimal " "addition and subtraction operators \ngenerates the " "following output. It displays the sum and \n" "difference of several pairs of Decimal objects." ); // Create pairs of Decimal objects. ShowDecimalSumDiff( Decimal(1230000000,0,0,false,7), Decimal::Parse( "0.0012300" ) ); ShowDecimalSumDiff( Decimal::Parse( "123.456789" ), Decimal::Parse( "0.006789" ) ); ShowDecimalSumDiff( Decimal::Parse( "12345678900000000" ), Decimal::Parse( "0.00000000123456789" ) ); ShowDecimalSumDiff( Decimal::Parse( "123456789.0123456789" ), Decimal::Parse( "123456789.1123456789" ) ); } /* This example of the Decimal addition and subtraction operators generates the following output. It displays the sum and difference of several pairs of Decimal objects. Decimal Left 123.0000000 Decimal Right 0.0012300 Left + Right 123.0012300 Left - Right 122.9987700 Decimal Left 123.456789 Decimal Right 0.006789 Left + Right 123.463578 Left - Right 123.450000 Decimal Left 12345678900000000 Decimal Right 0.00000000123456789 Left + Right 12345678900000000.000000001235 Left - Right 12345678899999999.999999998765 Decimal Left 123456789.0123456789 Decimal Right 123456789.1123456789 Left + Right 246913578.1246913578 Left - Right -0.1000000000 */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: