Decimal.ToOACurrency(Decimal) Method is used to convert the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.
Syntax: public static long ToOACurrency (decimal value); Here, it takes the decimal number to convert. Return Value: This method returns a 64-bit signed integer that contains the OLE Automation equivalent of value.
Below programs illustrate the use of Decimal.ToOACurrency() Method Example 1:
csharp
// C# program to demonstrate the // Decimal.ToOACurrency() Method using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
Decimal curr = 40;
// A 64-bit signed integer that contains
// the OLE Automation equivalent of value.
long value = Decimal.ToOACurrency(curr);
// Display the HashCode
Console.WriteLine("Equivalent long value is {0}", value);
}
} |
Output:
Equivalent long value is 400000
Example 2:
csharp
// C# program to demonstrate the // Decimal.ToOACurrency() Method using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// calling get() method
Console.WriteLine("Equivalent long value are respectively");
get (20);
get (30);
get (40);
get (4294967295);
}
// defining get() method
public static void get ( decimal curr)
{
// getting Equivalent decimal value
// using ToOACurrency() method
long value = Decimal.ToOACurrency(curr);
// Display the HashCode
Console.WriteLine("{0}", value);
}
} |
Reference: