다음을 통해 공유


Decimal.ToUInt64 메서드

지정된 Decimal의 값을 64비트 부호 없는 정수로 변환합니다.

이 메서드는 CLS 규격이 아닙니다.  

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

구문

‘선언
<CLSCompliantAttribute(False)> _
Public Shared Function ToUInt64 ( _
    d As Decimal _
) As ULong
‘사용 방법
Dim d As Decimal
Dim returnValue As ULong

returnValue = Decimal.ToUInt64(d)
[CLSCompliantAttribute(false)] 
public static ulong ToUInt64 (
    decimal d
)
[CLSCompliantAttribute(false)] 
public:
static usigned long long ToUInt64 (
    Decimal d
)
/** @attribute CLSCompliantAttribute(false) */ 
public static UInt64 ToUInt64 (
    Decimal d
)
CLSCompliantAttribute(false) 
public static function ToUInt64 (
    d : decimal
) : ulong

매개 변수

  • d
    변환할 Decimal 값입니다.

반환 값

d의 값에 해당하는 64비트의 부호 없는 정수입니다.

예외

예외 형식 조건

OverflowException

d가 음수이거나 UInt64.MaxValue보다 큰 경우

설명

반환 값은 10진 값의 정수 부분입니다. 소수 자리는 잘립니다.

예제

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

' Example of the Decimal.ToInt64 and Decimal.ToUInt64 methods.
Imports System
Imports Microsoft.VisualBasic

Module DecimalToU_Int64Demo

    Dim formatter As String = "{0,25}{1,22}{2,22}"

    ' 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

    ' Convert the Decimal argument; catch exceptions that are thrown.
    Sub DecimalToU_Int64( argument As Decimal )

        Dim Int64Value    As Object
        Dim UInt64Value   As Object

        ' Convert the argument to a Long value.
        Try
            Int64Value = Decimal.ToInt64( argument )
        Catch ex As Exception
            Int64Value = GetExceptionType( ex )
        End Try

        ' Convert the argument to a UInt64 value.
        Try
            UInt64Value = Decimal.ToUInt64( argument )
        Catch ex As Exception
            UInt64Value = GetExceptionType( ex )
        End Try

        Console.WriteLine( formatter, argument, _
            Int64Value, UInt64Value )
    End Sub

    Sub Main( )

        Console.WriteLine( "This example of the " & vbCrLf & _
            "  Decimal.ToInt64( Decimal ) and " & vbCrLf & _
            "  Decimal.ToUInt64( Decimal ) " & vbCrLf & "methods " & _
            "generates the following output. It " & vbCrLf & _
            "displays several converted Decimal values." & vbCrLf )
        Console.WriteLine( formatter, "Decimal argument", _
            "Long/exception", "UInt64/exception" )
        Console.WriteLine( formatter, "----------------", _
            "--------------", "----------------" )

        ' Convert Decimal values and display the results.
        DecimalToU_Int64( 123D )
        DecimalToU_Int64( New Decimal( 123000, 0, 0, False, 3 ) )
        DecimalToU_Int64( 123.999D )
        DecimalToU_Int64( 18446744073709551615.999D )
        DecimalToU_Int64( 18446744073709551616D )
        DecimalToU_Int64( 9223372036854775807.999D )
        DecimalToU_Int64( 9223372036854775808D )
        DecimalToU_Int64( - 0.999D )
        DecimalToU_Int64( - 1D )
        DecimalToU_Int64( - 9223372036854775808.999D )
        DecimalToU_Int64( - 9223372036854775809D )
    End Sub 
End Module 

' This example of the
'   Decimal.ToInt64( Decimal ) and
'   Decimal.ToUInt64( Decimal )
' methods generates the following output. It
' displays several converted Decimal values.
' 
'          Decimal argument        Long/exception      UInt64/exception
'          ----------------        --------------      ----------------
'                       123                   123                   123
'                   123.000                   123                   123
'                   123.999                   123                   123
'  18446744073709551615.999     OverflowException  18446744073709551615
'      18446744073709551616     OverflowException     OverflowException
'   9223372036854775807.999   9223372036854775807   9223372036854775807
'       9223372036854775808     OverflowException   9223372036854775808
'                    -0.999                     0                     0
'                        -1                    -1     OverflowException
'  -9223372036854775808.999  -9223372036854775808     OverflowException
'      -9223372036854775809     OverflowException     OverflowException
// Example of the decimal.ToInt64 and decimal.ToUInt64 methods.
using System;

class DecimalToU_Int64Demo
{
    const string formatter = "{0,25}{1,22}{2,22}";

    // 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 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int64( decimal argument )
    {
        object Int64Value;
        object UInt64Value;

        // Convert the argument to a long value.
        try
        {
            Int64Value = decimal.ToInt64( argument );
        }
        catch( Exception ex )
        {
            Int64Value = GetExceptionType( ex );
        }

        // Convert the argument to a ulong value.
        try
        {
            UInt64Value = decimal.ToUInt64( argument );
        }
        catch( Exception ex )
        {
            UInt64Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument, 
            Int64Value, UInt64Value );
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the \n" +
            "  decimal.ToInt64( decimal ) and \n" +
            "  decimal.ToUInt64( decimal ) \nmethods " +
            "generates the following output. It \ndisplays " +
            "several converted decimal values.\n" );
        Console.WriteLine( formatter, "decimal argument", 
            "long/exception", "ulong/exception" );
        Console.WriteLine( formatter, "----------------", 
            "--------------", "---------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int64( 123M );
        DecimalToU_Int64( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int64( 123.999M );
        DecimalToU_Int64( 18446744073709551615.999M );
        DecimalToU_Int64( 18446744073709551616M );
        DecimalToU_Int64( 9223372036854775807.999M );
        DecimalToU_Int64( 9223372036854775808M );
        DecimalToU_Int64( - 0.999M );
        DecimalToU_Int64( - 1M );
        DecimalToU_Int64( - 9223372036854775808.999M );
        DecimalToU_Int64( - 9223372036854775809M );
    }
}

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

         decimal argument        long/exception       ulong/exception
         ----------------        --------------       ---------------
                      123                   123                   123
                  123.000                   123                   123
                  123.999                   123                   123
 18446744073709551615.999     OverflowException  18446744073709551615
     18446744073709551616     OverflowException     OverflowException
  9223372036854775807.999   9223372036854775807   9223372036854775807
      9223372036854775808     OverflowException   9223372036854775808
                   -0.999                     0                     0
                       -1                    -1     OverflowException
 -9223372036854775808.999  -9223372036854775808     OverflowException
     -9223372036854775809     OverflowException     OverflowException
*/
// Example of the Decimal::ToInt64 and Decimal::ToUInt64 methods.
using namespace System;
#define formatter "{0,25}{1,22}{2,22}"

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


// Convert the Decimal argument; catch exceptions that are thrown.
void DecimalToU_Int64( Decimal argument )
{
   Object^ Int64Value;
   Object^ UInt64Value;
   
   // Convert the argument to an __int64 value.
   try
   {
      Int64Value = Decimal::ToInt64( argument );
   }
   catch ( Exception^ ex ) 
   {
      Int64Value = GetExceptionType( ex );
   }

   
   // Convert the argument to an unsigned __int64 value.
   try
   {
      UInt64Value = Decimal::ToUInt64( argument );
   }
   catch ( Exception^ ex ) 
   {
      UInt64Value = GetExceptionType( ex );
   }

   Console::WriteLine( formatter, argument, Int64Value, UInt64Value );
}

int main()
{
   Console::WriteLine( "This example of the \n"
   "  Decimal::ToInt64( Decimal ) and \n"
   "  Decimal::ToUInt64( Decimal ) \nmethods "
   "generates the following output. It \ndisplays "
   "several converted Decimal values.\n" );
   Console::WriteLine( formatter, "Decimal argument", "__int64/exception", "unsigned __int64" );
   Console::WriteLine( formatter, "----------------", "-----------------", "----------------" );
   
   // Convert Decimal values and display the results.
   DecimalToU_Int64( Decimal::Parse(  "123" ) );
   DecimalToU_Int64( Decimal(123000,0,0,false,3) );
   DecimalToU_Int64( Decimal::Parse(  "123.999" ) );
   DecimalToU_Int64( Decimal::Parse(  "18446744073709551615.999" ) );
   DecimalToU_Int64( Decimal::Parse(  "18446744073709551616" ) );
   DecimalToU_Int64( Decimal::Parse(  "9223372036854775807.999" ) );
   DecimalToU_Int64( Decimal::Parse(  "9223372036854775808" ) );
   DecimalToU_Int64( Decimal::Parse(  "-0.999" ) );
   DecimalToU_Int64( Decimal::Parse(  "-1" ) );
   DecimalToU_Int64( Decimal::Parse(  "-9223372036854775808.999" ) );
   DecimalToU_Int64( Decimal::Parse(  "-9223372036854775809" ) );
}

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

         Decimal argument     __int64/exception      unsigned __int64
         ----------------     -----------------      ----------------
                      123                   123                   123
                  123.000                   123                   123
                  123.999                   123                   123
 18446744073709551615.999     OverflowException  18446744073709551615
     18446744073709551616     OverflowException     OverflowException
  9223372036854775807.999   9223372036854775807   9223372036854775807
      9223372036854775808     OverflowException   9223372036854775808
                   -0.999                     0                     0
                       -1                    -1     OverflowException
 -9223372036854775808.999  -9223372036854775808     OverflowException
     -9223372036854775809     OverflowException     OverflowException
*/
// Example of the decimal.ToInt64 and decimal.ToUInt64 methods.
import System.*;

class DecimalToU_Int64Demo
{
    private static final String formatter = "{0,25}{1,22}{2,22}";
   
    // 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);
    }
       
    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int64(System.Decimal argument) 
    {
        Object int64Value;
        Object uint64Value;
          
        // Convert the argument to a long value.
        try {
            int64Value = (System.Int64)System.Decimal.ToInt64(argument);
        }
        catch(System.Exception  ex){
            int64Value = GetExceptionType(ex);
        }
          
        // Convert the argument to a ulong value.
        try {
            uint64Value = System.Decimal.ToUInt64(argument);
        }
        catch(System.Exception  ex){  
            uint64Value = GetExceptionType(ex);
        }
        Console.WriteLine(formatter, argument, int64Value, uint64Value);
    }
   
    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the \n" 
            + "  decimal.ToInt64( decimal ) and \n" 
            + "  decimal.ToUInt64( decimal ) \nmethods " 
            + "generates the following output. It \ndisplays " 
            + "several converted decimal values.\n"));
        
        Console.WriteLine(formatter, "decimal argument", "long/exception", 
            "ulong/exception");
        Console.WriteLine(formatter, "----------------", "--------------", 
            "---------------");
      
        // Convert decimal values and display the results.
        DecimalToU_Int64(new System.Decimal(123));
        DecimalToU_Int64(new System.Decimal(123000, 0, 0, false, (ubyte)3));
        DecimalToU_Int64(new System.Decimal(123.999));
        DecimalToU_Int64(new System.Decimal(18446744073709551615.999));
        DecimalToU_Int64(new System.Decimal(18446744073709551616F));
        DecimalToU_Int64(new System.Decimal(9223372036854775807.999));
        DecimalToU_Int64(new System.Decimal(9223372036854775808F));
        DecimalToU_Int64(new System.Decimal(-0.999));
        DecimalToU_Int64(new System.Decimal(-1));
        DecimalToU_Int64(new System.Decimal(-9223372036854775808.999));
        DecimalToU_Int64(new System.Decimal(-9223372036854775809F));
    }
}

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

         decimal argument        long/exception       ulong/exception
         ----------------        --------------       ---------------
                      123                   123                   123
                  123.000                   123                   123
                  123.999                   123                   123
     18446744073709600000     OverflowException     OverflowException
     18446740000000000000     OverflowException  18446740000000000000
      9223372036854780000     OverflowException   9223372036854780000
      9223372000000000000   9223372000000000000   9223372000000000000
                   -0.999                     0                     0
                       -1                    -1     OverflowException
     -9223372036854780000     OverflowException     OverflowException
     -9223372000000000000  -9223372000000000000     OverflowException
*/

플랫폼

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 네임스페이스
UInt64