This documentation is archived and is not being maintained.

Convert.ToDouble Method (Object)

.NET Framework 1.1

Converts the value of the specified Object to a double-precision floating point number.

[Visual Basic]
Overloads Public Shared Function ToDouble( _
   ByVal value As Object _
) As Double
public static double ToDouble(
 object value
public: static double ToDouble(
 Object* value
public static function ToDouble(
   value : Object
) : double;


An Object that implements the IConvertible interface or a null reference (Nothing in Visual Basic).

Return Value

A double-precision floating point number equivalent to the value of value, or zero if value is a null reference (Nothing in Visual Basic).


Exception Type Condition
InvalidCastException value does not implement IConvertible.


The return value is the result of invoking the IConvertible.ToDouble method of the underlying type of value.


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

[Visual Basic] 
Public Sub ConvertDoubleString(ByVal doubleVal As Double)

    Dim stringVal As String

    ' A conversion from Double to String cannot overflow.       
    stringVal = System.Convert.ToString(doubleVal)
    System.Console.WriteLine("{0} as a String is: {1}", _
                              doubleVal, stringVal)

        doubleVal = System.Convert.ToDouble(stringVal)
        System.Console.WriteLine("{0} as a Double is: {1}", _
                                  stringVal, doubleVal)
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in String-to-Double conversion.")
    Catch exception As System.FormatException
        System.Console.WriteLine( _
            "The string is not formatted as a Double.")
    Catch exception As System.ArgumentException
        System.Console.WriteLine("The string is null.")
    End Try

End Sub

public void ConvertDoubleString(double doubleVal) {
    string    stringVal;     

    // A conversion from Double to string cannot overflow.       
    stringVal = System.Convert.ToString(doubleVal);
    System.Console.WriteLine("{0} as a string is: {1}",
        doubleVal, stringVal);

    try {
        doubleVal = System.Convert.ToDouble(stringVal);
        System.Console.WriteLine("{0} as a double is: {1}",
            stringVal, doubleVal);
    catch (System.OverflowException) {
            "Conversion from string-to-double overflowed.");
    catch (System.FormatException) {
            "The string was not formatted as a double.");
    catch (System.ArgumentException) {
            "The string pointed to null.");


   void ConvertDoubleString(double doubleVal)
      String*    stringVal;     

      // A conversion from Double to String* cannot overflow.       
      stringVal = System::Convert::ToString(doubleVal);
      System::Console::WriteLine(S" {0} as a String* is: {1}",
         __box(doubleVal), stringVal);

      try {
         doubleVal = System::Convert::ToDouble(stringVal);
         System::Console::WriteLine(S" {0} as a double is: {1}",
            stringVal, __box(doubleVal));
      } catch (System::OverflowException*) {
         System::Console::WriteLine(S"Conversion from String*-to-double overflowed.");
      } catch (System::FormatException*) {
         System::Console::WriteLine(S"The String* was not formatted as a double.");
      } catch (System::ArgumentException*) {
         System::Console::WriteLine(S"The String* pointed to null.");

[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.


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

See Also

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