This documentation is archived and is not being maintained.

Convert.ToDouble Method (Boolean)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function ToDouble( _
   ByVal value As Boolean _
) As Double
[C#]
public static double ToDouble(
 bool value
);
[C++]
public: static double ToDouble(
 bool value
);
[JScript]
public static function ToDouble(
   value : Boolean
) : double;

Parameters

value
A Boolean value.

Return Value

The number 1 if value is true; otherwise, 0.

Example

[Visual Basic, C#, C++] The following code sample illustrates the conversion of a Boolean value to a Double one, using ToDouble.

[Visual Basic] 
Public Sub ConvertDoubleBool(ByVal doubleVal As Double)
    Dim boolVal As Boolean

    'Double to Boolean conversion cannot overflow.
    boolVal = System.Convert.ToBoolean(doubleVal)
    System.Console.WriteLine("{0} as a Boolean is: {1}.", _
                              doubleVal, boolVal)

    'Boolean to Double conversion cannot overflow.
    doubleVal = System.Convert.ToDouble(boolVal)
    System.Console.WriteLine("{0} as a Double is: {1}.", _
                              boolVal, doubleVal)
End Sub

[C#] 
public void ConvertDoubleBool(double doubleVal) {
    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);
}

[C++] 

public __gc class ConvertSnippet
{
public:
   void ConvertDoubleBool(double doubleVal)
   {
      bool boolVal;
      // Double to bool conversion cannot overflow.
      boolVal = System::Convert::ToBoolean(doubleVal);
      System::Console::WriteLine(S" {0} as a Boolean is: {1}.",
         __box(doubleVal), __box(boolVal));

      // bool to double conversion cannot overflow.
      doubleVal = System::Convert::ToDouble(boolVal);
      System::Console::WriteLine(S" {0} as a double is: {1}.",
         __box(boolVal), __box(doubleVal));
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Convert Class | Convert Members | System Namespace | Convert.ToDouble Overload List

Show: