เมธอด Decimal.ToUInt32() ใน C# ใช้แปลงค่าของ Decimal ที่ระบุเป็นจำนวนเต็ม 32 บิตไม่มีเครื่องหมายที่เทียบเท่า
ไวยากรณ์
public static uint ToUInt32 (decimal val);
พารามิเตอร์ val คือจำนวนทศนิยมที่ต้องการแปลง
ตัวอย่าง
ตัวอย่างที่ 1: แปลง 0.001 เป็น UInt32 (ผลลัพธ์เป็น 0)
using System;
public class Demo {
public static void Main(){
Decimal val = 0.001m;
Console.WriteLine("Decimal value = " + val);
uint res = Decimal.ToUInt32(val);
Console.WriteLine("32-bit unsigned integer = " + res);
}
}
ผลลัพธ์
Decimal value = 0.001 32-bit unsigned integer = 0
ตัวอย่างเพิ่มเติม
ตัวอย่างที่ 2: แปลง 67.487 เป็น UInt32
using System;
public class Demo {
public static void Main(){
Decimal val = 67.487m;
Console.WriteLine("Decimal value = " + val);
uint res = Decimal.ToUInt32(val);
Console.WriteLine("32-bit unsigned integer = " + res);
}
}
ผลลัพธ์
Decimal value = 67.487 32-bit unsigned integer = 67