Phương thức Decimal.ToUInt32() trong C# chuyển đổi giá trị Decimal được chỉ định thành số nguyên không dấu 32-bit tương đương.
Cú pháp
public static uint ToUInt32(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 = 0.001m;
Console.WriteLine("Decimal value = " + val);
uint res = Decimal.ToUInt32(val);
Console.WriteLine("32-bit unsigned integer = " + res);
}
}
Đầu ra
Decimal value = 0.001 32-bit unsigned integer = 0
Ví dụ 2
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);
}
}
Đầu ra
Decimal value = 67.487 32-bit unsigned integer = 67