Mega Code Archive

 
Categories / C# / Data Types
 

Converts decimal number to byte

using System; public class MainClass {     public static void Main()     {         byte byteVal = 123;         decimal decimalVal;         // Byte to decimal conversion will not overflow.         decimalVal = System.Convert.ToDecimal(byteVal);         System.Console.WriteLine("The byte as a decimal is {0}.",             decimalVal);         // Decimal to byte conversion can overflow.         byteVal = System.Convert.ToByte(decimalVal);         System.Console.WriteLine("The Decimal as a byte is {0}.", byteVal);     } }