Export (0) Print
Expand All

Decimal.ToUInt64 Method

Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.

This API is not CLS-compliant. 

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

'Declaration
<CLSCompliantAttribute(False)> _
Public Shared Function ToUInt64 ( _
	d As Decimal _
) As ULong
'Usage
Dim d As Decimal 
Dim returnValue As ULong 

returnValue = Decimal.ToUInt64(d)

Parameters

d
Type: System.Decimal

A Decimal value to convert.

Return Value

Type: System.UInt64
A 64-bit unsigned integer equivalent to the value of d.

ExceptionCondition
OverflowException

d is negative or greater than UInt64.MaxValue.

The return value is the integral part of the decimal value; fractional digits are truncated.

The following code example converts Decimal numbers to UInt64 values using the ToUInt64 method.

' 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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft