次の方法で共有


Convert.ToDouble メソッド (Decimal)

指定した Decimal の数値を、それと等価な倍精度浮動小数点数に変換します。

Overloads Public Shared Function ToDouble( _
   ByVal value As Decimal _) As Double
[C#]
public static double ToDouble(decimalvalue);
[C++]
public: static double ToDouble(Decimalvalue);
[JScript]
public static function ToDouble(
   value : Decimal) : double;

パラメータ

戻り値

value の値と等価な倍精度浮動小数点数。

使用例

[Visual Basic, C#, C++] ToDouble を使用して、 Decimal の値を Double の値に変換する方法については、次のコード例を参照してください。渡された DecimalMaxValue よりも大きい場合、 OverflowException が発生します。

 
Public Sub ConvertDoubleDecimal(ByVal doubleVal As Double)

    Dim decimalVal As Decimal

    ' Conversion from Double to Decimal cannot overflow.
    decimalVal = System.Convert.ToDecimal(doubleVal)
    System.Console.WriteLine("{0} as a Decimal is: {1}", _
                              doubleVal, decimalVal)

    ' Decimal to Double conversion can overflow.
    Try
        doubleVal = System.Convert.ToDouble(decimalVal)
        System.Console.WriteLine("{0} as a Double is: {1}", _
                                  decimalVal, doubleVal)
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in Decimal-to-Double conversion.")
    End Try
End Sub

[C#] 
public void ConvertDoubleDecimal(double doubleVal){
    
    decimal decimalVal;
    
    // Conversion from double to decimal cannot overflow.
    decimalVal = System.Convert.ToDecimal(doubleVal);
    System.Console.WriteLine ("{0} as a decimal is: {1}",
        doubleVal, decimalVal);
    
    // Decimal to double conversion can overflow.
    try {
        doubleVal = System.Convert.ToDouble(decimalVal);
        System.Console.WriteLine("{0} as a double is: {1}",
            decimalVal, doubleVal);
    } 
    catch (System.OverflowException) {
        System.Console.WriteLine(
            "Overflow in decimal-to-double conversion.");
    }

}

[C++] 

   void ConvertDoubleDecimal(double doubleVal)
   {
      Decimal decimalVal;

      // Conversion from double to decimal cannot overflow.
      decimalVal = System::Convert::ToDecimal(doubleVal);
      System::Console::WriteLine (S" {0} as a decimal is: {1}",
         __box(doubleVal), __box(decimalVal));

      // Decimal to double conversion can overflow.
      try {
         doubleVal = System::Convert::ToDouble(decimalVal);
         System::Console::WriteLine(S" {0} as a double is: {1}",
            __box(decimalVal), __box(doubleVal));
      } catch (System::OverflowException*) {
         System::Console::WriteLine(S"Overflow in decimal-to-double conversion.");
      }

   }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Convert クラス | Convert メンバ | System 名前空間 | Convert.ToDouble オーバーロードの一覧