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

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

Phương thức Decimal.ToUInt64() trong C# chuyển đổi giá trị Decimal được chỉ định thành số nguyên không dấu 64-bit tương đương.

Cú pháp

public static ulong ToUInt64(decimal val);

Tham số val là số decimal cần chuyển đổi.

Ví dụ 1

using System;
public class Demo
{
    public static void Main()
    {
        Decimal val = 99.29m;
        Console.WriteLine("Decimal value = " + val);
        ulong res = Decimal.ToUInt64(val);
        Console.WriteLine("64-bit unsigned integer = " + res);
    }
}

Đầu ra

Decimal value = 99.29
64-bit unsigned integer = 99

Ví dụ 2

using System;
public class Demo
{
    public static void Main()
    {
        Decimal val = 0.001m;
        Console.WriteLine("Decimal value = " + val);
        ulong res = Decimal.ToUInt64(val);
        Console.WriteLine("64-bit unsigned integer = " + res);
    }
}

Đầu ra

Decimal value = 0.001
64-bit unsigned integer = 0