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 System
using System;
// create class
class DecimalMultiplier
{
// main method
static void Main()
{
// create decimal values
decimal decimalNumberOne = 34.668m;
decimal decimalNumberTwo = 4.9999m;
decimal decimalNumberThree = 899.2m;
decimal decimalNumberFour = 1.2m;
// multiply decimal values
Console.WriteLine(Decimal.Multiply(decimalNumberOne, decimalNumberTwo));
Console.WriteLine(Decimal.Multiply(decimalNumberThree, decimalNumberFour));
}
}

Code explanation

  • Lines 10–13: We create some decimal variables, decimalNumberOne, decimalNumberTwo, decimalNumberThree, and decimalNumberFour. Then, we initialize them with some values.

  • Line 16: We use the Decimal.Multiply() method to multiply decimalNumberOne with decimalNumberTwo and print the result.

  • Line 17: We use the Decimal.Multiply() method to multiply decimalNumberThree with decimalNumberFour and print the result.