This documentation is archived and is not being maintained.

# Decimal Explicit Conversion (Decimal to UInt64)

Visual Studio 2010

Converts a Decimal to a 64-bit unsigned integer.

This API is not CLS-compliant.

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

## Syntax

```static explicit operator unsigned long long (
Decimal value
)
```

#### Parameters

value
Type: System::Decimal
The value to convert.

#### Return Value

Type: System::UInt64
A 64-bit unsigned integer that represents the converted Decimal.

## Exceptions

ExceptionCondition
OverflowException

value is negative or greater than UInt64::MaxValue.

## Remarks

This operator supports the explicit conversion of a Decimal to a UInt64. The syntax for such explicit conversions is language-dependent, and individual language compilers can provide different implementations and return different results. The example illustrates the different return values when you explicitly convert a Decimal value to a UInt64 value by using C# and Visual Basic. To perform a conversion that is independent of language, you can call the ToUInt64 or the Convert::ToUInt64(Decimal) method.

## Examples

The following code example converts Decimal numbers to UInt64 values using the explicit Decimal to UInt64 conversion.

```
// Example of the explicit conversions from Decimal to __int64 and
// Decimal to unsigned __int64.
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 = (__int64)argument;
}
catch ( Exception^ ex )
{
Int64Value = GetExceptionType( ex );
}

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

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

int main()
{
Console::WriteLine( "This example of the explicit conversions from Decimal to "
"__int64 \nand Decimal to unsigned __int64 generates the "
"following output. \nIt displays several converted Decimal "
"values.\n" );
Console::WriteLine( formatter, "Decimal argument", "__int64", "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 explicit conversions from Decimal to __int64
and Decimal to unsigned __int64 generates the following output.
It displays several converted Decimal values.

Decimal argument               __int64      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
*/

```

## Version Information

#### .NET Framework

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

#### .NET Framework Client Profile

Supported in: 4, 3.5 SP1

#### Portable Class Library

Supported in: Portable Class Library

## Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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