The Decimal.Negate()
method is a C# method that is used to get the result of a decimal value when it is multiplied by a negative value (-1
).
public static decimal Negate (decimal d);
d
: The decimal value that we want to multiply by a negative value.The Decimal.Negate()
method returns a decimal number that is the negative of d
. If d
is zero, then the method returns a zero.
// use systemusing System;// create classclass NegateDecimal{// main methodstatic void Main(){// negate decimal valuesConsole.WriteLine(Decimal.Negate(334.45m));Console.WriteLine(Decimal.Negate(-7.899m));Console.WriteLine(Decimal.Negate(-1.323m));}}
334.45m
and print the result.-7.899m
and print the result.Decimal.Negate()
method to negate -1.323m
and print the result.When we run the code, we get the negative values of the decimal numbers that we negated.