Convert double-precision floating-point number to byte in CSharp
Description
The following code shows how to convert double-precision floating-point number to byte.
Example
using System;// w w w . jav a2 s.c o m
public class MainClass
{
public static void Main()
{
double doubleVal = 123.123;
byte byteVal = 0;
byteVal = System.Convert.ToByte(doubleVal);
System.Console.WriteLine("{0} as a byte is: {1}.",
doubleVal, byteVal);
// Byte to double conversion cannot overflow.
doubleVal = System.Convert.ToDouble(byteVal);
System.Console.WriteLine("{0} as a double is: {1}.", byteVal, doubleVal);
}
}
The code above generates the following result.