×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# program for type conversion from double to int

C# example of type conversion – here, we are writing a C# program – it will convert a double value to an integer. By IncludeHelp Last updated : April 15, 2023

C# double To int Conversion

Given a double type of variable, we have to convert it into an integer in C#.

Syntax

    int_variable = (int)double_variable;

Example

    Input:
    double a = 123456.789;
    int b = 0;

    //type conversion
    b = (int)a;

    Output:
    a: 123456.789
    b: 123456

C# code for type conversion from double to int

// C# program for type conversion from double to int 

using System;
using System.IO;
using System.Text;

namespace IncludeHelp {
  class Test {
    // Main Method 
    static void Main(string[] args) {
      double a = 123456.789;
      int b = 0;

      //type conversion
      b = (int) a;

      Console.WriteLine("value of a: {0}", a);
      Console.WriteLine("value of b: {0}", b);

      //hit ENTER to exit the program
      Console.ReadLine();
    }
  }
}

Output

value of a: 123456.789
value of b: 123456

C# Basic Programs »


Related Programs

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.