The Decimal.ToUInt64()
method converts the value of the specified decimal to the equivalent 64-bit unsigned integer.
public static ulong ToUInt64 (decimal d);
d
: This is the decimal value that we want to convert to the equivalent 64-bit unsigned integer.
A UInt64
value is returned. It is a 64-bit unsigned integer equivalent of the specified decimal value.
// use Systemusing System;// create classclass DecimalTOUInt64{// main methodstatic void Main(){// create decimal valuesdecimal d1 = 34.5m;decimal d2 = 2.4356345m;decimal d3 = 10.34m;// convert to UInt64// and print valueConsole.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt64(d1),Decimal.ToUInt64(d1).GetType());Console.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt64(d2),Decimal.ToUInt64(d2).GetType());Console.WriteLine("Value = {0}, type = {1}",Decimal.ToUInt64(d3),Decimal.ToUInt64(d3).GetType());}}
Lines 10-12: We create variables d1
, d2
, and d3
of type decimal
and assign decimal values to them.
Lines 16-26: We convert each value to an unsigned 64-bit integer using the Decimal.ToUInt64()
method. Then we print the converted values and their type.