Convert double to integer and catch OverflowException : OverflowException « Data Types « C# / C Sharp






Convert double to integer and catch OverflowException

 

using System;
using System.Globalization;

public class Example
{
    public static void Main()
    {

        double dbl2 = 1111111111.999;
        try
        {
            int number2 = (int)dbl2;
            Console.WriteLine(number2);
        }
        catch (OverflowException)
        {
            Console.WriteLine("{0} is out of range of an Int32.", dbl2);
        }

    }
}

   
  








Related examples in the same category

1.Convert long to integer and catch the OverflowException