The Decimal.ToUInt32()
method is used to convert a decimal value to its equivalent 32-bit unsigned integer in C#.
public static ushort ToUInt32 (decimal d);
d
: The decimal value we want to convert to a 32-bit unsigned integer.The return value is an UInt32
, a 32-bit unsigned integer that is the equivalent of d
.
// use Systemusing System;// create classclass DecimalTOUInt32{// main methodstatic void Main(){// create decimal valuesdecimal d1 = 34.5m;decimal d2 = 2.4356345m;decimal d3 = 10.34m;// convert to UInt32// and print valueConsole.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt32(d1),Decimal.ToUInt32(d1).GetType());Console.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt32(d2),Decimal.ToUInt32(d2).GetType());Console.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt32(d3),Decimal.ToUInt32(d3).GetType());}}
Lines 10–12: We create decimal variables d1
, d2
, and d3
, and initialize them with decimal values.
Lines 16–26: We use the Decimal.ToUInt32()
method to convert each value to an unsigned 32-bit integer and print the results.