用于将类型从double转换为int的C#程序

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

给定双重类型的变量,我们必须在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

用于将类型从double转换为int的C#代码

// 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
翻译自:
Given a double type of variable, we have to convert it into an integer in C#. 给定双重类型的变量,我们必须在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 用于将类型从double转换为int的C#代码 // 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 翻译自:
经验分享 程序员 微信小程序 职场和发展