Convert.ToSingle Method in C#


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

767 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements