当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Decimal.ToOACurrency()用法及代码示例


Decimal.ToOACurrency(Decimal)方法用于将指定的Decimal值转换为等效的OLE自动化货币值,该值包含在64位带符号整数中。

用法:  public static long ToOACurrency (decimal value);
Here, it takes the decimal number to convert.

返回值:此方法返回一个64位带符号整数,其中包含与OLE Automation等效的值。


下面的程序演示了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

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Decimal.ToOACurrency() Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。