當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。