【发布时间】:2019-06-17 20:05:57
【问题描述】:
我有一个变量来自:
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");
}
}
【问题讨论】:
-
因为
5 % 10是 5 而不是0 -
Get the decimal part from a double 可能重复如果它没有小数 => 它是一个整数。
-
您的测试会检查最后一位是否为零。你可以试试
if ((r % l) == 0) -
你认为
1.0e100是整数吗?请注意,1e100 == 10...0 (100 zeroes)超出int.MaxValue