C# Program to convert a Double to an Integer Value


To convert a Double value to an integer value, use the Convert.ToInt32() method.

Int32 represents a 32-bit signed integer.

Let’s say the following is our double value.

double val = 21.34;

Now to convert it to Int32.

int res = Convert.ToInt32(val);

Let us see the complete example.

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      double val = 21.34;
      int res = Convert.ToInt32(val);
      Console.WriteLine("Converted double {0} to integer {1} ", val, res);
   }
}

Output

Converted double 21.34 to integer 21

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements