Decimal.ToSingle() Method in C#


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

Syntax

Following is the syntax −

public static float ToSingle (decimal val);

Above, Val is the decimal number to convert.

Example

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

using System;
public class Demo {
   public static void Main(){
      Decimal val = 0.00000007575833m;
      Console.WriteLine("Decimal value = "+val);
      float res = Decimal.ToSingle(val);
      Console.WriteLine("Single-precision floating-point number = "+res);
   }
}

Output

This will produce the following output −

Decimal value = 0.00000007575833
Single-precision floating-point number = 7.575833E-08

Example

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

using System;
public class Demo {
   public static void Main(){
      Decimal val = 8767576576m;
      Console.WriteLine("Decimal value = "+val);
      float res = Decimal.ToSingle(val);
      Console.WriteLine("Single-precision floating-point number = "+res);
   }
}

Output

This will produce the following output −

Decimal value = 8767576576
Single-precision floating-point number = 8.767576E+09
raja
Published on 06-Nov-2019 08:02:35
Advertisements