This documentation is archived and is not being maintained.

# Decimal.ToOACurrency Method

Visual Studio 2010

Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.

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

## Syntax

```public static long ToOACurrency(
decimal value
)
```

#### Parameters

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

#### Return Value

Type: System.Int64
A 64-bit signed integer that contains the OLE Automation equivalent of value.

## Examples

The following code example uses the ToOACurrency method to convert Decimal numbers to the equivalent OLE Automation Currency values that are contained in Int64 fields.

```
// Example of the decimal.ToOACurrency method.
using System;

class DecimalToOACurrencyDemo
{
const string dataFmt = "{0,31}{1,27}";

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

// Display the decimal.ToOACurrency parameter and the result
// or exception.
public static void ShowDecimalToOACurrency( decimal Argument )
{
// Catch the exception if ToOACurrency( ) throws one.
try
{
long oaCurrency = decimal.ToOACurrency( Argument );
Console.WriteLine( dataFmt, Argument, oaCurrency );
}
catch( Exception ex )
{
Console.WriteLine( dataFmt, Argument,
GetExceptionType( ex ) );
}
}

public static void Main( )
{
Console.WriteLine( "This example of the " +
"decimal.ToOACurrency( ) method generates \nthe " +
"following output. It displays the argument as a " +
"decimal \nand the OLE Automation Currency value " +
"as a long.\n" );
Console.WriteLine( dataFmt, "Argument",
"OA Currency or Exception" );
Console.WriteLine( dataFmt, "--------",
"------------------------" );

// Convert decimal values to OLE Automation Currency values.
ShowDecimalToOACurrency( 0M );
ShowDecimalToOACurrency( 1M );
ShowDecimalToOACurrency( 1.0000000000000000000000000000M );
ShowDecimalToOACurrency( 100000000000000M );
ShowDecimalToOACurrency( 100000000000000.00000000000000M );
ShowDecimalToOACurrency( 10000000000000000000000000000M );
ShowDecimalToOACurrency( 0.000000000123456789M );
ShowDecimalToOACurrency( 0.123456789M );
ShowDecimalToOACurrency( 123456789M );
ShowDecimalToOACurrency( 123456789000000000M );
ShowDecimalToOACurrency( 4294967295M );
ShowDecimalToOACurrency( 18446744073709551615M );
ShowDecimalToOACurrency( -79.228162514264337593543950335M );
ShowDecimalToOACurrency( -79228162514264.337593543950335M );
}
}

/*
This example of the decimal.ToOACurrency( ) method generates
the following output. It displays the argument as a decimal
and the OLE Automation Currency value as a long.

Argument   OA Currency or Exception
--------   ------------------------
0                          0
1                      10000
1.0000000000000000000000000000                      10000
100000000000000        1000000000000000000
100000000000000.00000000000000        1000000000000000000
10000000000000000000000000000          OverflowException
0.000000000123456789                          0
0.123456789                       1235
123456789              1234567890000
123456789000000000          OverflowException
4294967295             42949672950000
18446744073709551615          OverflowException
-79.228162514264337593543950335                    -792282
-79228162514264.337593543950335        -792281625142643376
*/

```

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

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