Mega Code Archive

 
Categories / VB.Net / Development
 

Convert ToByte (Decimal) converts decimal number to 8-bit unsigned integer

Class Sample    Public Shared Sub Main()             Dim byteVal As Byte             Dim decimalVal As Decimal                      byteVal = 12             decimalVal = System.Convert.ToDecimal(byteVal)             System.Console.WriteLine("The byte as a decimal is {0}.",decimalVal)             Try                 byteVal = System.Convert.ToByte(decimalVal)                 System.Console.WriteLine("The Decimal as a byte is {0}.",byteVal)             Catch exception As System.OverflowException                 System.Console.WriteLine("OverflowException")             End Try     End Sub End Class