Decimal.Divide() Method in C#


The Decimal.Divide() method in C# is used to divide two specified Decimal values.

Syntax

Following is the syntax −

public static decimal Divide (decimal val1, decimal val2);

Above, val1 is the dividend, whereas val2 is the divisor.

Example

Let us now see an example to implement the Decimal.Divide() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 65.15m;
      Decimal val2 = 5.15m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("After Division = "+(Decimal.Divide(val1,val2)));
   }
}

Output

This will produce the following output −

Decimal 1 = 65.15
Decimal 2 = 5.15
After Division = 12.650485436893203883495145631

Example

Let us now see another example to implement the Decimal.Divide() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 1.0m;
      Decimal val2 = 1.0m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("After Division = "+(Decimal.Divide(val1,val2)));
   }
}

Output

This will produce the following output −

Decimal 1 = 1.0
Decimal 2 = 1.0
After Division = 1

Updated on: 05-Nov-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements