Decimal.ToOACurrency(Decimal)方法用于将指定的Decimal值转换为等效的OLE自动化货币值,该值包含在64位带符号整数中。
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.
下面的程序说明了Decimal.ToOACurrency()方法的用法
范例1:
// 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);
}
}
输出:
Equivalent long value is 400000
范例2:
// 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 respectivily");
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);
}
}
输出:
Equivalent long value are respectivily
200000
300000
400000
42949672950000
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.decimal.tooacurrency?view=netframework-4.7.2