C# Convert ToBoolean(Single)
Description
Convert ToBoolean(Single)
converts the value of the
specified single-precision floating-point number to an equivalent Boolean
value.
Syntax
Convert.ToBoolean(Single)
has the following syntax.
public static bool ToBoolean(
float value
)
Parameters
Convert.ToBoolean(Single)
has the following parameters.
value
- The single-precision floating-point number to convert.
Returns
Convert.ToBoolean(Single)
method returns true if value is not zero; otherwise, false.
Example
The following example converts an array of Single values to Boolean values.
/*w ww.j a v a 2s .c o m*/
using System;
public class MainClass{
public static void Main(String[] argv){
float[] numbers = { Single.MinValue, -123.1234f, 20e-15f, 0f,
12345e-10f, 123.3398f, Single.MaxValue };
bool result;
foreach (float number in numbers)
{
result = Convert.ToBoolean(number);
Console.WriteLine("{0,-15} --> {1}", number, result);
}
}
}
The code above generates the following result.