共用方式為


Convert.ToDouble Method (Decimal)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the value of the specified Decimal number to an equivalent double-precision floating point number.

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

Syntax

'Declaration
Public Shared Function ToDouble ( _
    value As Decimal _
) As Double
public static double ToDouble(
    decimal value
)

Parameters

Return Value

Type: System.Double
A double-precision floating point number equivalent to the value of value.

Examples

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

Public Sub ConvertDoubleDecimal(ByVal decimalVal As Decimal)

   Dim doubleVal As Double

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

   ' Conversion from Double to Decimal can overflow.
   Try
      decimalVal = System.Convert.ToDecimal(doubleVal)
      outputBlock.Text &= String.Format("{0} as a Decimal is: {1}", _
                               doubleVal, decimalVal) & vbCrLf
   Catch exception As System.OverflowException
      outputBlock.Text &= String.Format( _
          "Overflow in Double-to-Decimal conversion.") & vbCrLf
   End Try

End Sub
public void ConvertDoubleDecimal(decimal decimalVal)
{
   double doubleVal;

   // Decimal to double conversion cannot overflow.
   doubleVal = System.Convert.ToDouble(decimalVal);
   outputBlock.Text += String.Format("{0} as a double is: {1}",
         decimalVal, doubleVal) + "\n";

   // Conversion from double to decimal can overflow.
   try
   {
      decimalVal = System.Convert.ToDecimal(doubleVal);
      outputBlock.Text += String.Format("{0} as a decimal is: {1}",
         doubleVal, decimalVal) + "\n";
   }
   catch (System.OverflowException)
   {
      outputBlock.Text += String.Format(
         "Overflow in double-to-double conversion.") + "\n";
   }
}

Version Information

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

Platforms

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