Decimal.Negate Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns the result of multiplying the specified Decimal value by negative one.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- d
- Type: System.Decimal
A Decimal.
Return Value
Type: System.DecimalA Decimal with the value of d, but the opposite sign.
-or-
Zero, if d is zero.
The following code example uses the Negate method to change the sign of several Decimal values.
// Example of the decimal.Negate, decimal.Floor, and decimal.Truncate // methods. using System; class Example { const string dataFmt = "{0,-30}{1,26}"; // Display decimal parameters and the method results. public static void ShowDecimalFloorNegTrunc(System.Windows.Controls.TextBlock outputBlock, decimal Argument) { outputBlock.Text += "\n"; outputBlock.Text += String.Format(dataFmt, "decimal Argument", Argument) + "\n"; outputBlock.Text += String.Format(dataFmt, "decimal.Negate( Argument )", decimal.Negate(Argument)) + "\n"; outputBlock.Text += String.Format(dataFmt, "decimal.Floor( Argument )", decimal.Floor(Argument)) + "\n"; outputBlock.Text += String.Format(dataFmt, "decimal.Truncate( Argument )", decimal.Truncate(Argument)) + "\n"; } public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += "This example of the \n" + " decimal.Negate( decimal ), \n" + " decimal.Floor( decimal ), and \n" + " decimal.Truncate( decimal ) \n" + "methods generates the following output." + "\n"; // Create pairs of decimal objects. ShowDecimalFloorNegTrunc(outputBlock, 0M); ShowDecimalFloorNegTrunc(outputBlock, 123.456M); ShowDecimalFloorNegTrunc(outputBlock, -123.456M); ShowDecimalFloorNegTrunc(outputBlock, new decimal(1230000000, 0, 0, true, 7)); ShowDecimalFloorNegTrunc(outputBlock, -9999999999.9999999999M); } } /* This example of the decimal.Negate( decimal ), decimal.Floor( decimal ), and decimal.Truncate( decimal ) methods generates the following output. decimal Argument 0 decimal.Negate( Argument ) 0 decimal.Floor( Argument ) 0 decimal.Truncate( Argument ) 0 decimal Argument 123.456 decimal.Negate( Argument ) -123.456 decimal.Floor( Argument ) 123 decimal.Truncate( Argument ) 123 decimal Argument -123.456 decimal.Negate( Argument ) 123.456 decimal.Floor( Argument ) -124 decimal.Truncate( Argument ) -123 decimal Argument -123.0000000 decimal.Negate( Argument ) 123.0000000 decimal.Floor( Argument ) -123 decimal.Truncate( Argument ) -123 decimal Argument -9999999999.9999999999 decimal.Negate( Argument ) 9999999999.9999999999 decimal.Floor( Argument ) -10000000000 decimal.Truncate( Argument ) -9999999999 */
Show: