c# - 如何检查我的双变量是否是整数?

标签 c# asp.net

<分区>

我有一个变量来自:

double result = myList.Count / mySeptum;

我想做以下事情:

if( result == int ) {
      //Do Something...
} 
else{
      //Do another thing...
}

我该怎么做?

我也试过这个,但是没用:

if ( result%10 == 0 ){
...
}

举个例子:

private void button2_Click(object sender, EventArgs e)
{
    int r = 10;
    int l = 2;
    double d = r / l;

    if (d % 10 == 0)
    {
        Console.WriteLine("INTEGER");
    }
    else
    {
        Console.WriteLine("DOUBLE");
    }
}

最佳答案

例如:

double d = 1.0;
bool isInt = d == (int)d;

取模:

double d = 1.0;
bool isInt = d % 1 == 0;

关于c# - 如何检查我的双变量是否是整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54340696/

相关文章:

c# - 传递目录路径时出错

c# - 在整个应用程序中禁用 TAB 导航

c# - 不完整的消息(C# TCP/IP 客户端)

c# - LINQ InvalidCastException 错误

c# - 使类在运行时可序列化

c# - 添加新绑定(bind)时 IIS 8.5 会回收

c# - 将日期时间字符串与阿拉伯字符串连接起来

asp.net - 将 ASP.NET ConnectionString 设置为特定的域用户

asp.net - 奇怪的 ASP.Net 错误 : .net 4.6.1,VS2015 - 不支持内插字符串?

c# - 使用 C# 从 UIElement 获取 WPF 屏幕截图 JPG