Decimal.Negate() Method in C#
Last Updated :
30 Jan, 2019
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
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = 127.97m;
Decimal value = Decimal.Negate(a);
Console.WriteLine( "The negative value " +
"is : {0}" , value);
}
}
|
Output:
The negative value is : -127.97
Example 2: When a is negative
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = -12.39m;
Decimal value = Decimal.Negate(a);
Console.WriteLine( "The value is : {0}" ,
value);
}
}
|
Output:
The value is : 12.39
Example 3: If a is zero.
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Decimal a = 0.00m;
Decimal value = Decimal.Negate(a);
Console.WriteLine( "The Negate value " +
"is : {0}" , value);
}
}
|
Output:
The Negate value is : 0.00
Reference:
Share your thoughts in the comments
Please Login to comment...