Decimal.Negate() Method in C#

This method is used to get the result of multiplying the specified Decimal value by negative one.

Syntax: public static decimal Negate (decimal a);

Parameter:
a: This parameter specifies the decimal which will be converted.

Return Value: A decimal number with the value of a, but the opposite sign. But zero, if a is zero.

Below programs illustrate the use of Decimal.Negate(Decimal) Method:

Example 1: When a is positive

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Decimal.Negate(Decimal) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Declaring the decimal variable
        Decimal a = 127.97m;
  
        // using Negate() method;
        Decimal value = Decimal.Negate(a);
  
        // Display the negative value
        Console.WriteLine("The negative value "+
                             "is : {0}", value);
    }
}

chevron_right


Output:

The negative value is : -127.97

Example 2: When a is negative

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Decimal.Negate(Decimal) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Declaring the decimal variable
        Decimal a = -12.39m;
  
        // using Negate() method;
        Decimal value = Decimal.Negate(a);
  
        // Display the value after
        // using negate method
        Console.WriteLine("The value is : {0}",
                                        value);
    }
}

chevron_right


Output:

The value is : 12.39

Example 3: If a is zero.

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Decimal.Negate(Decimal) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Declaring the decimal variable
        Decimal a = 0.00m;
  
        // using Negate() method;
        Decimal value = Decimal.Negate(a);
  
        // Display the Negate value
        Console.WriteLine("The Negate value "+
                           "is : {0}", value);
    }
}

chevron_right


Output:

The Negate value is : 0.00

Reference:



My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.