ToDouble Method (Object)

Convert.ToDouble Method (Object)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

'Declaration
Public Shared Function ToDouble ( _
	value As Object _
) As Double

Parameters

value
Type: System.Object
An Object that implements the IConvertible interface or Nothing.

Return Value

Type: System.Double
A double-precision floating point number equivalent to the value of value, or zero if value is Nothing.

ExceptionCondition
InvalidCastException

value does not implement IConvertible.

If value is not Nothing, this method wraps a call to the IConvertible.ToDouble implementation of the underlying type of value.

The following code sample illustrates the conversion of a String to Double using ToDouble.


Public Sub ConvertDoubleString(ByVal doubleVal As Double)

   Dim stringVal As String

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

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

End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft