Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Decimal::ToOACurrency Method

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)
public:
static long 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.

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 namespace System;
#define dataFmt "{0,31}{1,27}" 

// Get the exception type name; remove the namespace prefix.
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. 
void ShowDecimalToOACurrency( Decimal Argument )
{

   // Catch the exception if ToOACurrency( ) throws one. 
   try
   {
      __int64 oaCurrency = Decimal::ToOACurrency( Argument );
      Console::WriteLine( dataFmt, Argument, oaCurrency );
   }
   catch ( Exception^ ex ) 
   {
      Console::WriteLine( dataFmt, Argument, GetExceptionType( ex ) );
   }

}

int 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 an __int64.\n" );
   Console::WriteLine( dataFmt, "Argument", "OA Currency or Exception" );
   Console::WriteLine( dataFmt, "--------", "------------------------" );

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

/*
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 an __int64.

                       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
*/

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.