Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Decimal.FromOACurrency() trong C#

Phương thức Decimal.FromOACurrency() trong C# được dùng để chuyển đổi số nguyên 64-bit có dấu được chỉ định, chứa giá trị OLE Automation Currency, thành giá trị Decimal tương đương.

Cú pháp

Cú pháp như sau:

public static decimal FromOACurrency(long val);

Tham số val là giá trị OLE Automation Currency.

Ví dụ 1 - Chuyển đổi giá trị bình thường

using System;

public class Demo
{
    public static void Main()
    {
        long val = 978576L;
        decimal res = Decimal.FromOACurrency(val);
        Console.WriteLine("Decimal Value = " + res);
    }
}

Kết quả

Decimal Value = 97.8576

Ví dụ 2 - Chuyển đổi long.MinValue

using System;

public class Demo
{
    public static void Main()
    {
        long val = long.MinValue;
        decimal res = Decimal.FromOACurrency(val);
        Console.WriteLine("Decimal Value = " + res);
    }
}

Kết quả

Decimal Value = -922337203685477.5808