What is the Decimal.Multiply() method in C#?
Overview
The Decimal.Multiply() method is used to multiply two decimal values. Decimal.Multiply() takes two decimal values as parameters. The first parameter is the multiplicand and the second is the multiplier.
This method returns the result of multiplying the two decimal values that are taken as parameters.
Syntax
public static decimal Multiply (decimal d1, decimal d2);
Parameters
-
d1: The first decimal value, which is the multiplicand. -
d2: The second decimal value, which is the multiplier.
Return value
The Decimal.Multiply method returns the result of multiplying the two decimal values, d1 and d2.
Code example
// use Systemusing System;// create classclass DecimalMultiplier{// main methodstatic void Main(){// create decimal valuesdecimal decimalNumberOne = 34.668m;decimal decimalNumberTwo = 4.9999m;decimal decimalNumberThree = 899.2m;decimal decimalNumberFour = 1.2m;// multiply decimal valuesConsole.WriteLine(Decimal.Multiply(decimalNumberOne, decimalNumberTwo));Console.WriteLine(Decimal.Multiply(decimalNumberThree, decimalNumberFour));}}
Code explanation
-
Lines 10–13: We create some decimal variables,
decimalNumberOne,decimalNumberTwo,decimalNumberThree, anddecimalNumberFour. Then, we initialize them with some values. -
Line 16: We use the
Decimal.Multiply()method to multiplydecimalNumberOnewithdecimalNumberTwoand print the result. -
Line 17: We use the
Decimal.Multiply()method to multiplydecimalNumberThreewithdecimalNumberFourand print the result.