Mohanapriya R Mohanapriya R
Updated date May 08, 2024
In this article, we will learn how to easily convert double values to integers in C#.
  • 4.3k
  • 0
  • 0

How to Converting Double to Integer in C#?

In this program, we have a double value 10.75 that we want to convert to an integer. The conversion is performed by casting the double value to an integer using (int)doubleValue. The (int) is a type cast operator indicating the conversion to the integer type.

using System;

class Program
{
    static void Main(string[] args)
    {
        // Double value to be converted
        double doubleValue = 10.75;

        // Convert double to integer
        int intValue = (int)doubleValue;

        // Output the results
        Console.WriteLine("Double value: " + doubleValue);
        Console.WriteLine("Integer value: " + intValue);
    }
}

Output:

Let's run the program and see the output:

Double value: 10.75
Integer value: 10

As expected, the double value 10.75 is converted to an integer, resulting in 10. Notice that the fractional part .75 is truncated during the conversion process.

Comments (0)

There are no comments. Be the first to comment!!!