다음을 통해 공유


Decimal.ToOACurrency 메서드

지정된 Decimal 값을 64비트의 부호 있는 정수에 포함된 해당 OLE Automation Currency 값으로 변환합니다.

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

구문

‘선언
Public Shared Function ToOACurrency ( _
    value As Decimal _
) As Long
‘사용 방법
Dim value As Decimal
Dim returnValue As Long

returnValue = Decimal.ToOACurrency(value)
public static long ToOACurrency (
    decimal value
)
public:
static long long ToOACurrency (
    Decimal value
)
public static long ToOACurrency (
    Decimal value
)
public static function ToOACurrency (
    value : decimal
) : long

매개 변수

반환 값

value에 해당하는 OLE Automation이 포함된 64비트의 부호 있는 정수입니다.

예제

다음 코드 예제에서는 ToOACurrency 메서드를 사용하여 Decimal 숫자를 Int64 필드에 포함된 동일한 OLE Automation Currency 값으로 변환합니다.

' Example of the Decimal.ToOACurrency method. 
Imports System
Imports Microsoft.VisualBasic

Module DecimalToOACurrencyDemo
    
    Const dataFmt As String = "{0,31}{1,27}"

    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception ) As String

        Dim exceptionType   As String = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1 )
    End Function

    ' Display the Decimal.ToOACurrency parameter and the result 
    ' or exception.
    Sub ShowDecimalToOACurrency( Argument As Decimal )

        ' Catch the exception if ToOACurrency( ) throws one.
        Try
            Dim oaCurrency As Long = Decimal.ToOACurrency( Argument )
            Console.WriteLine( dataFmt, Argument, _
                oaCurrency )

        Catch ex As Exception
            Console.WriteLine( dataFmt, Argument, _
                GetExceptionType( ex ) )
        End Try
    End Sub

    Sub Main( )
        Console.WriteLine( "This example of the " & _
            "Decimal.ToOACurrency( ) method generates " & vbCrLf & _
            "the following output. It displays the argument as " & _
            "a Decimal " & vbCrLf & "and the OLE Automation " & _
            "Currency value as a Long." & vbCrLf )
        Console.WriteLine( dataFmt, "Argument", _
            "OA Currency or Exception" )
        Console.WriteLine( dataFmt, "--------", _
            "------------------------" )

        ' Convert Decimal values to OLE Automation Currency values.
        ShowDecimalToOACurrency( 0D )
        ShowDecimalToOACurrency( 1D )
        ShowDecimalToOACurrency( _
            Decimal.Parse( "1.0000000000000000000000000000" ) )
        ShowDecimalToOACurrency( 100000000000000D )
        ShowDecimalToOACurrency( _
            Decimal.Parse( "100000000000000.00000000000000" ) )
        ShowDecimalToOACurrency( 10000000000000000000000000000D )
        ShowDecimalToOACurrency( 0.000000000123456789D ) 
        ShowDecimalToOACurrency( 0.123456789D ) 
        ShowDecimalToOACurrency( 123456789D ) 
        ShowDecimalToOACurrency( 123456789000000000D ) 
        ShowDecimalToOACurrency( 4294967295D ) 
        ShowDecimalToOACurrency( 18446744073709551615D ) 
        ShowDecimalToOACurrency( -79.228162514264337593543950335D ) 
        ShowDecimalToOACurrency( -79228162514264.337593543950335D ) 
    End Sub
End Module 

' This example of the Decimal.ToOACurrency( ) method generates
' the following output. It displays the argument as a Decimal
' and the OLE Automation Currency value as a Long.
' 
'                        Argument   OA Currency or Exception
'                        --------   ------------------------
'                               0                          0
'                               1                      10000
'  1.0000000000000000000000000000                      10000
'                 100000000000000        1000000000000000000
'  100000000000000.00000000000000        1000000000000000000
'   10000000000000000000000000000          OverflowException
'            0.000000000123456789                          0
'                     0.123456789                       1235
'                       123456789              1234567890000
'              123456789000000000          OverflowException
'                      4294967295             42949672950000
'            18446744073709551615          OverflowException
' -79.228162514264337593543950335                    -792282
' -79228162514264.337593543950335        -792281625142643376
// Example of the decimal.ToOACurrency method. 
using System;

class DecimalToOACurrencyDemo
{
    const string dataFmt = "{0,31}{1,27}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Display the decimal.ToOACurrency parameter and the result 
    // or exception.
    public static void ShowDecimalToOACurrency( decimal Argument )
    {
        // Catch the exception if ToOACurrency( ) throws one.
        try
        {
            long oaCurrency = decimal.ToOACurrency( Argument );
            Console.WriteLine( dataFmt, Argument, oaCurrency );
        }
        catch( Exception ex )
        {
            Console.WriteLine( dataFmt, Argument, 
                GetExceptionType( ex ) );
        }
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the " +
            "decimal.ToOACurrency( ) method generates \nthe " +
            "following output. It displays the argument as a " +
            "decimal \nand the OLE Automation Currency value " +
            "as a long.\n" );
        Console.WriteLine( dataFmt, "Argument", 
            "OA Currency or Exception" );
        Console.WriteLine( dataFmt, "--------", 
            "------------------------" );

        // Convert decimal values to OLE Automation Currency values.
        ShowDecimalToOACurrency( 0M );
        ShowDecimalToOACurrency( 1M );
        ShowDecimalToOACurrency( 1.0000000000000000000000000000M );
        ShowDecimalToOACurrency( 100000000000000M );
        ShowDecimalToOACurrency( 100000000000000.00000000000000M );
        ShowDecimalToOACurrency( 10000000000000000000000000000M );
        ShowDecimalToOACurrency( 0.000000000123456789M );
        ShowDecimalToOACurrency( 0.123456789M );
        ShowDecimalToOACurrency( 123456789M );
        ShowDecimalToOACurrency( 123456789000000000M );
        ShowDecimalToOACurrency( 4294967295M );
        ShowDecimalToOACurrency( 18446744073709551615M );
        ShowDecimalToOACurrency( -79.228162514264337593543950335M );
        ShowDecimalToOACurrency( -79228162514264.337593543950335M );
    }
}

/*
This example of the decimal.ToOACurrency( ) method generates
the following output. It displays the argument as a decimal
and the OLE Automation Currency value as a long.

                       Argument   OA Currency or Exception
                       --------   ------------------------
                              0                          0
                              1                      10000
 1.0000000000000000000000000000                      10000
                100000000000000        1000000000000000000
 100000000000000.00000000000000        1000000000000000000
  10000000000000000000000000000          OverflowException
           0.000000000123456789                          0
                    0.123456789                       1235
                      123456789              1234567890000
             123456789000000000          OverflowException
                     4294967295             42949672950000
           18446744073709551615          OverflowException
-79.228162514264337593543950335                    -792282
-79228162514264.337593543950335        -792281625142643376
*/
// Example of the Decimal::ToOACurrency method. 
using namespace System;
#define dataFmt "{0,31}{1,27}"

// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
   String^ exceptionType = ex->GetType()->ToString();
   return exceptionType->Substring( exceptionType->LastIndexOf( '.' ) + 1 );
}


// Display the Decimal::ToOACurrency parameter and the result 
// or exception.
void ShowDecimalToOACurrency( Decimal Argument )
{
   
   // Catch the exception if ToOACurrency( ) throws one.
   try
   {
      __int64 oaCurrency = Decimal::ToOACurrency( Argument );
      Console::WriteLine( dataFmt, Argument, oaCurrency );
   }
   catch ( Exception^ ex ) 
   {
      Console::WriteLine( dataFmt, Argument, GetExceptionType( ex ) );
   }

}

int main()
{
   Console::WriteLine( "This example of the "
   "Decimal::ToOACurrency( ) method generates \nthe "
   "following output. It displays the argument as a "
   "Decimal \nand the OLE Automation Currency value "
   "as an __int64.\n" );
   Console::WriteLine( dataFmt, "Argument", "OA Currency or Exception" );
   Console::WriteLine( dataFmt, "--------", "------------------------" );
   
   // Convert Decimal values to OLE Automation Currency values.
   ShowDecimalToOACurrency( Decimal(0) );
   ShowDecimalToOACurrency( Decimal(1) );
   ShowDecimalToOACurrency( Decimal::Parse( "1.0000000000000000000000000000" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "100000000000000" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "100000000000000.00000000000000" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "10000000000000000000000000000" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "0.000000000123456789" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "0.123456789" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "123456789" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "123456789000000000" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "4294967295" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "18446744073709551615" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "-79.228162514264337593543950335" ) );
   ShowDecimalToOACurrency( Decimal::Parse( "-79228162514264.337593543950335" ) );
}

/*
This example of the Decimal::ToOACurrency( ) method generates
the following output. It displays the argument as a Decimal
and the OLE Automation Currency value as an __int64.

                       Argument   OA Currency or Exception
                       --------   ------------------------
                              0                          0
                              1                      10000
 1.0000000000000000000000000000                      10000
                100000000000000        1000000000000000000
 100000000000000.00000000000000        1000000000000000000
  10000000000000000000000000000          OverflowException
           0.000000000123456789                          0
                    0.123456789                       1235
                      123456789              1234567890000
             123456789000000000          OverflowException
                     4294967295             42949672950000
           18446744073709551615          OverflowException
-79.228162514264337593543950335                    -792282
-79228162514264.337593543950335        -792281625142643376
*/
// Example of the decimal.ToOACurrency method. 
import System.* ;

class DecimalToOACurrencyDemo
{
    private static String dataFmt = "{0,31}{1,27}";

    // Get the exception type name; remove the namespace prefix.
    public static String GetExceptionType(System.Exception ex) 
    {
        String exceptionType = ex.GetType().ToString();
        return exceptionType.Substring((exceptionType.LastIndexOf('.') + 1)) ;
    } //GetExceptionType

    // Display the decimal.ToOACurrency parameter and the result 
    // or exception.
    public static void ShowDecimalToOACurrency(System.Decimal Argument) 
    {
        // Catch the exception if ToOACurrency( ) throws one.
        try {
            long oaCurrency = System.Decimal.ToOACurrency(Argument);
            Console.WriteLine(dataFmt,System.Convert.ToString(Argument),
                System.Convert.ToString(oaCurrency));
        }
        catch(System.Exception  ex){        
            Console.WriteLine(dataFmt, Argument, GetExceptionType(ex));
        }
    } //ShowDecimalToOACurrency

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the " 
            + "decimal.ToOACurrency( ) method generates \nthe "
            + "following output. It displays the argument as a " 
            + "decimal \nand the OLE Automation Currency value " 
            + "as a long.\n"));
        Console.WriteLine(dataFmt, "Argument", "OA Currency or Exception");
        Console.WriteLine(dataFmt, "--------", "------------------------");
        
        // Convert decimal values to OLE Automation Currency values.
        ShowDecimalToOACurrency(System.Convert.ToDecimal(0));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(1));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (1.0000000000000000000000000000));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(100000000000000D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (100000000000000.00000000000000));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (10000000000000000000000000000D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (0.000000000123456789));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(0.123456789));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(123456789));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(123456789000000000D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal(4294967295D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (18446744073709551615D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (-79.228162514264337593543950335D));
        ShowDecimalToOACurrency(System.Convert.ToDecimal
            (-79228162514264.337593543950335D));
    } //main
} //DecimalToOACurrencyDemo

/*
This example of the decimal.ToOACurrency( ) method generates
the following output. It displays the argument as a decimal
and the OLE Automation Currency value as a long.

                       Argument   OA Currency or Exception
                       --------   ------------------------
                              0                          0
                              1                      10000
 1.0000000000000000000000000000                      10000
                100000000000000        1000000000000000000
 100000000000000.00000000000000        1000000000000000000
  10000000000000000000000000000          OverflowException
           0.000000000123456789                          0
                    0.123456789                       1235
                      123456789              1234567890000
             123456789000000000          OverflowException
                     4294967295             42949672950000
           18446744073709551615          OverflowException
-79.228162514264337593543950335                    -792282
-79228162514264.337593543950335        -792281625142643376
*/

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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에서 지원

참고 항목

참조

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