Export (0) Print
Expand All

UInt64 to Decimal Conversion

.NET Framework 1.1

Converts a 64-bit unsigned integer to a Decimal.

This type conversion is not CLS-compliant. For more information about CLS compliance, see What is the Common Language Specification.

[Visual Basic]
<CLSCompliant(False)>
returnValue = Decimal.op_Implicit(value)
[C#]
[CLSCompliant(false)]
public static implicit operator decimal(
 ulong value
);
[C++]
[CLSCompliant(false)]
public: static Decimal op_Implicit(
 unsigned __int64 value
);
[JScript]
returnValue = value;

[Visual Basic] In Visual Basic, you can use the conversion operators defined by a type, but you cannot define your own.

[JScript] In JScript, you can use the conversion operators defined by a type, but you cannot define your own.

Arguments [Visual Basic, JScript]

value
A 64-bit unsigned integer.

Parameters [C#, C++]

value
A 64-bit unsigned integer.

Return Value

A Decimal that represents the converted 64-bit unsigned integer.

Example

[Visual Basic, C#, C++] The following code example converts UInt64 values to Decimal numbers using the UInt64 to Decimal conversion. This conversion is implicit in C#, but requires the op_Implicit operator in Visual Basic and C++. Implicit conversions to Decimal use other methods in these languages.

[Visual Basic] 
' Example of the op_Implicit conversion from UInt64 to Decimal.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Module DecimalFromUInt64Demo

    Const formatter As String = _
        "{0,20}{1,21}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}"
 
    ' Convert the UInt64 argument and display the Decimal value.
    Sub DecimalFromUInt64( argument As UInt64 )

        Dim decValue    As Decimal
        Dim bits( )     As Integer
          
        ' The compiler invokes a constructor in Visual Basic 
        ' unless op_Implicit is explicitly called.
        decValue = Decimal.op_Implicit( argument )

        ' Display the Decimal and its binary representation.
        bits = Decimal.GetBits( decValue )
        Console.WriteLine( formatter, argument, decValue, _
            bits( 3 ), bits( 2 ), bits( 1 ), bits( 0 ) )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the op_Implicit conversion from " & _
            "UInt64 to Decimal generates the " & vbCrLf & _
            "following output. It displays the Decimal value " & _
            "and its binary representation." & vbCrLf )
        Console.WriteLine( formatter, "UInt64 argument", _
            "Decimal value", "bits(3)", "bits(2)", _
            "bits(1)", "bits(0)" )
        Console.WriteLine( formatter, "---------------", _
            "-------------", "-------", "-------", _
            "-------", "-------" )
          
        ' Convert UInt64 values and display the results.
        DecimalFromUInt64( UInt64.Parse( "0" ) ) 
        DecimalFromUInt64( UInt64.Parse( "18446744073709551615" ) )
        DecimalFromUInt64( UInt64.Parse( "FFFFFFFFFFFF", _
            NumberStyles.HexNumber ) )
        DecimalFromUInt64( UInt64.Parse( "123456789123456789" ) ) 
        DecimalFromUInt64( UInt64.Parse( "1000000000000000" ) )
    End Sub 
End Module

' This example of the op_Implicit conversion from UInt64 to Decimal generates the
' following output. It displays the Decimal value and its binary representation.
'
'      UInt64 argument        Decimal value   bits(3)  bits(2)  bits(1)  bits(0)
'      ---------------        -------------   -------  -------  -------  -------
'                    0                    0  00000000 00000000 00000000 00000000
' 18446744073709551615 18446744073709551615  00000000 00000000 FFFFFFFF FFFFFFFF
'      281474976710655      281474976710655  00000000 00000000 0000FFFF FFFFFFFF
'   123456789123456789   123456789123456789  00000000 00000000 01B69B4B ACD05F15
'     1000000000000000     1000000000000000  00000000 00000000 00038D7E A4C68000

[C#] 
// Example of the implicit conversion from ulong to decimal.
using System;

class DecimalFromUInt64Demo
{
    const string formatter = 
        "{0,20}{1,21}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}";

    // Convert the ulong argument and display the decimal value.
    public static void DecimalFromUInt64( ulong argument )
    {
        decimal decValue;
        int[ ]  bits;

        // Display the decimal and its binary representation.
        decValue = argument;
        bits = decimal.GetBits( decValue );

        Console.WriteLine( formatter, argument, decValue, 
            bits[ 3 ], bits[ 2 ], bits[ 1 ], bits[ 0 ] );
    }

    public static void Main( )
    {
        Console.WriteLine( 
            "This example of the implicit conversion from ulong " +
            "to decimal generates the \nfollowing output. It " +
            "displays the decimal value and its binary " +
            "representation.\n" );
        Console.WriteLine( formatter, "ulong argument", 
            "decimal value", "bits[3]", "bits[2]", 
            "bits[1]", "bits[0]" );
        Console.WriteLine( formatter, "--------------", 
            "-------------", "-------", "-------", 
            "-------", "-------" );

        // Convert ulong values and display the results.
        DecimalFromUInt64( ulong.MinValue );
        DecimalFromUInt64( ulong.MaxValue );
        DecimalFromUInt64( 0xFFFFFFFFFFFF );
        DecimalFromUInt64( 123456789123456789 );
        DecimalFromUInt64( 1000000000000000 );
    }
}

/*
This example of the implicit conversion from ulong to decimal generates the
following output. It displays the decimal value and its binary representation.

      ulong argument        decimal value   bits[3]  bits[2]  bits[1]  bits[0]
      --------------        -------------   -------  -------  -------  -------
                   0                    0  00000000 00000000 00000000 00000000
18446744073709551615 18446744073709551615  00000000 00000000 FFFFFFFF FFFFFFFF
     281474976710655      281474976710655  00000000 00000000 0000FFFF FFFFFFFF
  123456789123456789   123456789123456789  00000000 00000000 01B69B4B ACD05F15
    1000000000000000     1000000000000000  00000000 00000000 00038D7E A4C68000
*/

[C++] 
// Example of the op_Implicit conversion from unsigned __int64 to 
// Decimal.
#using <mscorlib.dll>
using namespace System;

const __wchar_t* formatter = 
    L"{0,20}{1,21}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}";

// Convert the unsigned __int64 argument and display the Decimal value.
void DecimalFromInt64( unsigned __int64 argument )
{
    Decimal decValue;
    Int32   bits[ ];

    // The compiler invokes a constructor in the Managed Extensions 
    // for C++ unless op_Implicit is explicitly called.
    decValue = Decimal::op_Implicit( argument );

    // Display the Decimal and its binary representation.
    bits = Decimal::GetBits( decValue );
    Console::WriteLine( formatter, __box( argument ), 
        __box( decValue ), __box( bits[ 3 ] ), 
        __box( bits[ 2 ] ), __box( bits[ 1 ] ), __box( bits[ 0 ] ) );
}

void main( )
{
    Console::WriteLine( 
        S"This example of the op_Implicit conversion from unsigned " 
        S"__int64 to Decimal \ngenerates the following output. " 
        S"It displays the Decimal value and its \nbinary "
        S"representation.\n" );
    Console::WriteLine( formatter, S"unsigned __int64", 
        S"Decimal value", S"bits[3]", S"bits[2]", 
        S"bits[1]", S"bits[0]" );
    Console::WriteLine( formatter, S"----------------", 
        S"-------------", S"-------", S"-------", 
        S"-------", S"-------" );

    // Convert unsigned __int64 values and display the results.
    DecimalFromInt64( UInt64::MinValue );
    DecimalFromInt64( UInt64::MaxValue );
    DecimalFromInt64( 0xFFFFFFFFFFFF );
    DecimalFromInt64( 123456789123456789 );
    DecimalFromInt64( 1000000000000000 );
}

/*
This example of the op_Implicit conversion from unsigned __int64 to Decimal
generates the following output. It displays the Decimal value and its
binary representation.

    unsigned __int64        Decimal value   bits[3]  bits[2]  bits[1]  bits[0]
    ----------------        -------------   -------  -------  -------  -------
                   0                    0  00000000 00000000 00000000 00000000
18446744073709551615 18446744073709551615  00000000 00000000 FFFFFFFF FFFFFFFF
     281474976710655      281474976710655  00000000 00000000 0000FFFF FFFFFFFF
  123456789123456789   123456789123456789  00000000 00000000 01B69B4B ACD05F15
    1000000000000000     1000000000000000  00000000 00000000 00038D7E A4C68000
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Decimal Structure | Decimal Members | System Namespace | UInt64

Show:
© 2014 Microsoft