Decimal.ToDouble() Method in C#


The Decimal.ToDouble() method in C# is used to convert the value of the specified Decimal to the equivalent double-precision floating-point number.

Syntax

Following is the syntax −

public static double ToDouble (decimal val);

Above, Val is the decimal number to convert.

Example

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

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = -0.22m;
      Decimal val2 = -0.01m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Double res1 = Decimal.ToDouble(val1);
      Double res2 = Decimal.ToDouble(val2);
      Console.WriteLine("Double value1 (Decimal to Double) = "+res1);
      Console.WriteLine("Double value2 (Decimal to Double) = "+res2);
   }
}

Output

This will produce the following output −

Decimal 1 = -0.22
Decimal 2 = -0.01
Double value1 (Decimal to Double) = -0.22
Double value2 (Decimal to Double) = -0.01

Example

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

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 23828m;
      Decimal val2 = 976587687595766665m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Double res1 = Decimal.ToDouble(val1);
      Double res2 = Decimal.ToDouble(val2);
      Console.WriteLine("Double value1 (Decimal to Double) = "+res1);
      Console.WriteLine("Double value2 (Decimal to Double) = "+res2);
   }
}

Output

This will produce the following output −

Decimal 1 = 23828
Decimal 2 = 976587687595766665
Double value1 (Decimal to Double) = 23828
Double value2 (Decimal to Double) = 9.76587687595767E+17

Updated on: 12-Nov-2019

39 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements