This documentation is archived and is not being maintained.

# Decimal::Explicit Operator

Visual Studio 2008

Converts a Decimal to a 64-bit signed integer.

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

## Syntax

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

#### Parameters

value
Type: System::Decimal

A Decimal to convert.

#### Return Value

Type: System::Int64
A 64-bit signed integer that represents the converted Decimal.

## Exceptions

ExceptionCondition
OverflowException

value is less than Int64::MinValue or greater than Int64::MaxValue.

## Remarks

This operator supports the explicit conversion of a Decimal to a Int64. 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 an Int64 value by using C# and Visual Basic. To perform a conversion that is independent of language, you can call the ToInt64 or the Convert::ToInt64(Decimal) method.

## Examples

The following code example converts Decimal numbers to Int64 values using the explicit Decimal to Int64 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
*/
```

## Platforms

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.

## Version Information

#### .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