C# Convert ToBoolean(Double)

Description

Convert ToBoolean(Double) converts the value of the specified double-precision floating-point number to an equivalent Boolean value.

Syntax

Convert.ToBoolean(Double) has the following syntax.


public static bool ToBoolean(
  double value
)

Parameters

Convert.ToBoolean(Double) has the following parameters.

  • value - The double-precision floating-point number to convert.

Returns

Convert.ToBoolean(Double) method returns true if value is not zero; otherwise, false.

Example

The following example converts a Boolean to a Double and a Double to a Boolean value.


// w  ww.  j a  va  2  s .  c o  m
using System;
public class MainClass{
  public static void Main(String[] argv){  
     double doubleVal = 1.2;
     bool  boolVal;
     // Double to bool conversion cannot overflow.
     boolVal = System.Convert.ToBoolean(doubleVal);
     System.Console.WriteLine("{0} as a Boolean is: {1}.",
       doubleVal, boolVal);
     
     // bool to double conversion cannot overflow.
     doubleVal = System.Convert.ToDouble(boolVal);
     System.Console.WriteLine("{0} as a double is: {1}.",
       boolVal, doubleVal);

  }
}
     

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version