Convert double to byte in CSharp

Description

The following code shows how to convert double to byte.

Example


  //from  ww  w  . j av a 2s  .c o m
  
  
     

using System;

public class Example
{
   public static void Main()
   {
        
        double dbl2 = 3.99;
        try {
           byte value2 = (byte) dbl2;
           Console.WriteLine(value2);
        }
        catch (OverflowException) {
           Console.WriteLine("{0} is out of range of a byte.", dbl2);
        }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var