เมธอด Decimal.ToUInt64() ใน C# ใช้แปลงค่าของ Decimal ที่ระบุเป็นจำนวนเต็ม 64 บิตไม่มีเครื่องหมายที่เทียบเท่า
ไวยากรณ์
public static ulong ToUInt64 (decimal val);
พารามิเตอร์ val คือจำนวนทศนิยมที่ต้องการแปลง
ตัวอย่าง
ตัวอย่างที่ 1: แปลง 99.29 เป็น UInt64
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);
}
}
ผลลัพธ์
Decimal value = 99.29 64-bit unsigned integer = 99
ตัวอย่างเพิ่มเติม
ตัวอย่างที่ 2: แปลง 0.001 เป็น UInt64 (ผลลัพธ์เป็น 0)
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);
}
}
ผลลัพธ์
Decimal value = 0.001 64-bit unsigned integer = 0