C#-Programm zur Typkonvertierung von double nach int

C#-Programm zur Typkonvertierung von double nach int

C#-Beispiel für Typumwandlung – hier schreiben wir ein C#-Programm – es wird einen Double-Wert in eine Ganzzahl umwandeln .
Eingereicht von IncludeHelp , am 6. April 2019

Bei einem doppelten Variablentyp müssen wir ihn in C# in eine Ganzzahl umwandeln.

Syntax:

 int_variable = (int)double_variable;

Beispiel:

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

 //type conversion
 b = (int)a;

 Output:
 a: 123456.789
 b: 123456

C#-Code für die Typkonvertierung von double nach 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();
 }
 }
}

Ausgabe

value of a: 123456.789
value of b: 123456