Export (0) Print
Expand All

Decimal.Negate Method

Returns the result of multiplying the specified Decimal value by negative one.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static decimal Negate(
	decimal d
)

Parameters

d
Type: System.Decimal
A Decimal.

Return Value

Type: System.Decimal
A 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
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft