Convert.ToSingle Method in C#

CsharpProgrammingServer Side Programming

Convert a specified value to a single-precision floating-point number using the Convert.ToSingle() method in C#.

Here is our bool −

bool boolVal = false;

Now, let us use the ToSingle() method to convert the value to a single precision floating-point.

float floatVal;
floatVal = Convert.ToSingle(boolVal);

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      bool boolVal = false;
      float floatVal;
      floatVal = Convert.ToSingle(boolVal);
      Console.WriteLine("Converted {0} to {1}", boolVal, floatVal);
   }
}

Output

Converted False to 0
raja
Published on 11-Sep-2018 16:41:22
Advertisements