다음을 통해 공유


Decimal.ToDouble 메서드

지정된 Decimal의 값을 값이 같은 배정밀도 부동 소수점 숫자로 변환합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function ToDouble ( _
    d As Decimal _
) As Double
‘사용 방법
Dim d As Decimal
Dim returnValue As Double

returnValue = Decimal.ToDouble(d)
public static double ToDouble (
    decimal d
)
public:
static double ToDouble (
    Decimal d
)
public static double ToDouble (
    Decimal d
)
public static function ToDouble (
    d : decimal
) : double

매개 변수

  • d
    변환할 Decimal 값입니다.

반환 값

d와 값이 같은 배정밀도 부동 소수점 숫자입니다.

설명

배정밀도 부동 소수점 숫자가 Decimal보다 적은 수의 유효 숫자를 가지므로 이 연산은 반올림 오류를 발생시킬 수 있습니다.

예제

다음 코드 예제에서는 ToDouble 메서드를 사용하여 Decimal 숫자를 Double 값으로 변환합니다.

' Example of the Decimal.ToSingle and Decimal.ToDouble methods.
Imports System
Imports Microsoft.VisualBasic

Module DecimalToSgl_DblDemo

    Dim formatter As String = "{0,30}{1,17}{2,23}"

    ' Convert the Decimal argument; no exceptions are thrown.
    Sub DecimalToSgl_Dbl( argument As Decimal )

        Dim SingleValue   As Object
        Dim DoubleValue   As Object

        ' Convert the argument to a Single value.
        SingleValue = Decimal.ToSingle( argument )

        ' Convert the argument to a Double value.
        DoubleValue = Decimal.ToDouble( argument )

        Console.WriteLine( formatter, argument, _
            SingleValue, DoubleValue )
    End Sub

    Sub Main( )

        Console.WriteLine( "This example of the " & vbCrLf & _
            "  Decimal.ToSingle( Decimal ) and " & vbCrLf & _
            "  Decimal.ToDouble( Decimal ) " & vbCrLf & "methods " & _
            "generates the following output. It " & vbCrLf & _
            "displays several converted Decimal values." & vbCrLf )
        Console.WriteLine( formatter, "Decimal argument", _
            "Single", "Double" )
        Console.WriteLine( formatter, "----------------", _
            "------", "------" )

        ' Convert Decimal values and display the results.
        DecimalToSgl_Dbl( 0.0000000000000000000000000001D )
        DecimalToSgl_Dbl( 0.0000000000112233445566778899D )
        DecimalToSgl_Dbl( 123D )
        DecimalToSgl_Dbl( New Decimal( 123000000, 0, 0, False, 6 ) )
        DecimalToSgl_Dbl( 123456789.123456789D )
        DecimalToSgl_Dbl( 123456789123456789123456789D )
        DecimalToSgl_Dbl( Decimal.MinValue )
        DecimalToSgl_Dbl( Decimal.MaxValue )
    End Sub 
End Module 

' This example of the
'   Decimal.ToSingle( Decimal ) and
'   Decimal.ToDouble( Decimal )
' methods generates the following output. It
' displays several converted Decimal values.
' 
'               Decimal argument           Single                 Double
'               ----------------           ------                 ------
' 0.0000000000000000000000000001            1E-28                  1E-28
' 0.0000000000112233445566778899     1.122334E-11   1.12233445566779E-11
'                            123              123                    123
'                     123.000000              123                    123
'            123456789.123456789     1.234568E+08       123456789.123457
'    123456789123456789123456789     1.234568E+26   1.23456789123457E+26
' -79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
'  79228162514264337593543950335     7.922816E+28   7.92281625142643E+28
// Example of the decimal.ToSingle and decimal.ToDouble methods.
using System;

class DecimalToSgl_DblDemo
{
    static string formatter = "{0,30}{1,17}{2,23}";

    // Convert the decimal argument; no exceptions are thrown.
    public static void DecimalToSgl_Dbl( decimal argument )
    {
        object SingleValue;
        object DoubleValue;

        // Convert the argument to a float value.
        SingleValue = decimal.ToSingle( argument );

        // Convert the argument to a double value.
        DoubleValue = decimal.ToDouble( argument );

        Console.WriteLine( formatter, argument, 
            SingleValue, DoubleValue );
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the \n" +
            "  decimal.ToSingle( decimal ) and \n" +
            "  decimal.ToDouble( decimal ) \nmethods " +
            "generates the following output. It \ndisplays " +
            "several converted decimal values.\n" );
        Console.WriteLine( formatter, "decimal argument", 
            "float", "double" );
        Console.WriteLine( formatter, "----------------", 
            "-----", "------" );

        // Convert decimal values and display the results.
        DecimalToSgl_Dbl( 0.0000000000000000000000000001M );
        DecimalToSgl_Dbl( 0.0000000000123456789123456789M );
        DecimalToSgl_Dbl( 123M );
        DecimalToSgl_Dbl( new decimal( 123000000, 0, 0, false, 6 ) );
        DecimalToSgl_Dbl( 123456789.123456789M );
        DecimalToSgl_Dbl( 123456789123456789123456789M );
        DecimalToSgl_Dbl( decimal.MinValue );
        DecimalToSgl_Dbl( decimal.MaxValue );
    }
}

/*
This example of the
  decimal.ToSingle( decimal ) and
  decimal.ToDouble( decimal )
methods generates the following output. It
displays several converted decimal values.

              decimal argument            float                 double
              ----------------            -----                 ------
0.0000000000000000000000000001            1E-28                  1E-28
0.0000000000123456789123456789     1.234568E-11   1.23456789123457E-11
                           123              123                    123
                    123.000000              123                    123
           123456789.123456789     1.234568E+08       123456789.123457
   123456789123456789123456789     1.234568E+26   1.23456789123457E+26
-79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
 79228162514264337593543950335     7.922816E+28   7.92281625142643E+28
*/
// Example of the Decimal::ToSingle and Decimal::ToDouble methods.
using namespace System;
#define formatter "{0,30}{1,17}{2,23}"

// Convert the Decimal argument; no exceptions are thrown.
void DecimalToSgl_Dbl( Decimal argument )
{
   Object^ SingleValue;
   Object^ DoubleValue;
   
   // Convert the argument to a float value.
   SingleValue = Decimal::ToSingle( argument );
   
   // Convert the argument to a double value.
   DoubleValue = Decimal::ToDouble( argument );
   Console::WriteLine( formatter, argument, SingleValue, DoubleValue );
}

int main()
{
   Console::WriteLine( "This example of the \n"
   "  Decimal::ToSingle( Decimal ) and \n"
   "  Decimal::ToDouble( Decimal ) \nmethods "
   "generates the following output. It \ndisplays "
   "several converted Decimal values.\n" );
   Console::WriteLine( formatter, "Decimal argument", "float", "double" );
   Console::WriteLine( formatter, "----------------", "-----", "------" );
   
   // Convert Decimal values and display the results.
   DecimalToSgl_Dbl( Decimal::Parse(  "0.0000000000000000000000000001" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "0.0000000000123456789123456789" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123" ) );
   DecimalToSgl_Dbl( Decimal(123000000,0,0,false,6) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123456789.123456789" ) );
   DecimalToSgl_Dbl( Decimal::Parse(  "123456789123456789123456789" ) );
   DecimalToSgl_Dbl( Decimal::MinValue );
   DecimalToSgl_Dbl( Decimal::MaxValue );
}

/*
This example of the
  Decimal::ToSingle( Decimal ) and
  Decimal::ToDouble( Decimal )
methods generates the following output. It
displays several converted Decimal values.

              Decimal argument            float                 double
              ----------------            -----                 ------
0.0000000000000000000000000001            1E-28                  1E-28
0.0000000000123456789123456789     1.234568E-11   1.23456789123457E-11
                           123              123                    123
                    123.000000              123                    123
           123456789.123456789     1.234568E+08       123456789.123457
   123456789123456789123456789     1.234568E+26   1.23456789123457E+26
-79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
 79228162514264337593543950335     7.922816E+28   7.92281625142643E+28
*/
// Example of the decimal.ToSingle and decimal.ToDouble methods.
import System.* ;

class DecimalToSgl_DblDemo
{
    private static String formatter = "{0,30}{1,17}{2,23}";
      
    // Convert the decimal argument; no exceptions are thrown.
    public static void DecimalToSgl_Dbl(System.Decimal argument) 
    {
        Object singleValue;
        Object doubleValue;
      
        // Convert the argument to a float value.
        singleValue = (System.Single)System.Decimal.ToSingle(argument);
          
        // Convert the argument to a double value.
        doubleValue = (System.Double)System.Decimal.ToDouble(argument);
        Console.WriteLine(formatter, argument, singleValue, doubleValue);
    }
      
    public static void main(String[] args)
    {
        Console.WriteLine("This example of the \n" 
            + "  decimal.ToSingle( decimal ) and \n" 
            + "  decimal.ToDouble( decimal ) \nmethods " 
            + "generates the following output. It \ndisplays " 
            + "several converted decimal values.\n");
        
        Console.WriteLine(formatter, "decimal argument", "float", "double");
        Console.WriteLine(formatter, "----------------", "-----", "------");
            
        // Convert decimal values and display the results.
        DecimalToSgl_Dbl(new System.Decimal(0.0000000000000000000000000001));
        DecimalToSgl_Dbl(new System.Decimal(0.0000000000123456789123456789));
        DecimalToSgl_Dbl(new System.Decimal(123));
        DecimalToSgl_Dbl(new System.Decimal(123000000, 0, 0, false, (ubyte)6));
        DecimalToSgl_Dbl(new System.Decimal(123456789.123456789));
        DecimalToSgl_Dbl(new System.Decimal(123456789123456789123456789F));
        DecimalToSgl_Dbl(System.Decimal.MinValue);
        DecimalToSgl_Dbl(System.Decimal.MaxValue);
    }
}

/*
This example of the
  decimal.ToSingle( decimal ) and
  decimal.ToDouble( decimal )
methods generates the following output. It
displays several converted decimal values.

              decimal argument            float                 double
              ----------------            -----                 ------
0.0000000000000000000000000001            1E-28                  1E-28
   0.0000000000123456789123457     1.234568E-11   1.23456789123457E-11
                           123              123                    123
                    123.000000              123                    123
              123456789.123457     1.234568E+08       123456789.123457
   123456800000000000000000000     1.234568E+26           1.234568E+26
-79228162514264337593543950335    -7.922816E+28  -7.92281625142643E+28
 79228162514264337593543950335     7.922816E+28   7.92281625142643E+28
*/

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Decimal 구조체
Decimal 멤버
System 네임스페이스
Double