EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

Convert.ToDouble Method (Object)

May 02, 2013

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static double ToDouble(
	Object value
)

Parameters

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

Return Value

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

value does not implement IConvertible.

If value is not null, 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 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";
   }
}


Windows Phone OS

Supported in: 8.0, 7.1, 7.0

Windows Phone

Cela vous a-t-il été utile ?
(1500 caractères restants)
© 2013 Microsoft. Tous droits réservés.