Convert.ToBoolean Method (Double)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the value of the specified double-precision floating point number to an equivalent Boolean value.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function ToBoolean ( _
    value As Double _
) As Boolean
public static bool ToBoolean(
    double value
)

Parameters

  • value
    Type: System.Double
    A double-precision floating point number.

Return Value

Type: System.Boolean
true if value is not zero; otherwise, false.

Examples

The following code sample illustrates the use of the ToBoolean method, taking a Double as a parameter.

Public Sub ConvertDoubleBool(ByVal doubleVal As Double)
   Dim boolVal As Boolean

   'Double to Boolean conversion cannot overflow.
   boolVal = System.Convert.ToBoolean(doubleVal)
   outputBlock.Text &= String.Format("{0} as a Boolean is: {1}.", _
                             doubleVal, boolVal) & vbCrLf

   'Boolean to Double conversion cannot overflow.
   doubleVal = System.Convert.ToDouble(boolVal)
   outputBlock.Text &= String.Format("{0} as a Double is: {1}.", _
                             boolVal, doubleVal) & vbCrLf
End Sub
public void ConvertDoubleBool(double doubleVal)
{
   bool boolVal;
   // Double to bool conversion cannot overflow.
   boolVal = System.Convert.ToBoolean(doubleVal);
   outputBlock.Text += String.Format("{0} as a Boolean is: {1}.",
      doubleVal, boolVal) + "\n";

   // bool to double conversion cannot overflow.
   doubleVal = System.Convert.ToDouble(boolVal);
   outputBlock.Text += String.Format("{0} as a double is: {1}.",
      boolVal, doubleVal) + "\n";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.