The Decimal.ToByte()
method converts a specified decimal value to its equivalent 8-bit unsigned integer.
public static byte ToByte (decimal d);
d
: The decimal number to convert.The toByte()
method returns the 8-bit unsigned integer equivalent of the decimal number d
.
// use Systemusing System;// create classclass HelloWorld{// main methodstatic void Main(){// create decimal valuesdecimal d1 = 23.45m;decimal d2 = 0.45m;decimal d3 = 6.44m;// get the bytesConsole.WriteLine(Decimal.ToByte(d1));Console.WriteLine(Decimal.ToByte(d2));Console.WriteLine(Decimal.ToByte(d3));}}
Lines 11-13: We create decimal numbers whose 8-bit unsigned equivalent values we want to get.
Lines 16-18: We call the Decimal.Byte()
method on the decimal values we created and print the results to the console.