Convert.ToDouble Method (String)

Converts the specified String representation of a number to an equivalent double-precision floating point number.

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

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

Parameters

value
Type: System.String
A String containing a number to convert.

Return Value

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

ExceptionCondition
FormatException

value is not a number in a valid format.

OverflowException

value represents a number less than MinValue or greater than MaxValue.

The return value is the result of invoking the Double.Parse method on value.

If you prefer not to handle an exception if the conversion fails, you can call the Double.TryParse method instead. It returns a Boolean value that indicates whether the conversion succeeded or failed.

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


Public Sub CovertDoubleFloat(ByVal doubleVal As Double)
   Dim singleVal As Single = 0

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

   ' Conversion from Single to Double cannot overflow.
   doubleVal = System.Convert.ToDouble(singleVal)
   outputBlock.Text &= String.Format("{0} as a Double is: {1}", _
                             singleVal, doubleVal) & vbCrLf
End Sub


...


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


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

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

Community Additions

ADD
Show: