Convert.ToString Method (Double)

[ 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 double-precision floating point number to its equivalent String representation.

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

Syntax

Public Shared Function ToString ( _
    value As Double _
) As String
public static string ToString(
    double value
)

Parameters

Return Value

Type: System..::.String
The String equivalent of the value of value.

Remarks

This implementation is identical to Double..::.ToString.

Examples

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

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
public void ConvertDoubleString(double doubleVal)
{
   string stringVal;

   // 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) + "\n";

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

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

Convert Class

ToString Overload

System Namespace