Convert.ToInt32 Method in C#

CsharpProgrammingServer Side Programming

Use the Convert.ToInt32() method to convert a specified value to a 32-bit signed integer.

Let us take a double variable.

double doubleNum = 11.53;

Now, we will convert it to Int32 using the Convert.ToInt32 method.

int intNum;
ntNum = Convert.ToInt32(doubleNum);

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      double doubleNum = 11.53;
      int intNum;
      intNum = Convert.ToInt32(doubleNum);
      Console.WriteLine("Converted {0} to {1}", doubleNum, intNum);
   }
}

Output

Converted 11.53 to 12
raja
Published on 12-Sep-2018 09:22:49
Advertisements