iv'e tried using a for loop to filter out the null and nan values but still the nan value is added to the listview. this is just a part where the calculation is done.

double rs1 = (qz1 * c11) + (asg1 * c22) + (sw1 * c33) + (prj1 * c44) + (pxm1 * c55) + (atti1 * c66);
if(rs1 != double.NaN || rs1 != null)
{
lst.SubItems.Add(Math.Round(rs1, 2).ToString());
}
else
{
lst.SubItems.Add("0");
}
有帮助吗?

解决方案

use IsNan static function , read about it here

Your code should look like this

if(!Double.IsNaN(rs1)  || rs1 != null)

NaN with NaN will always return false, this is MSDN about NaN

Two NaN values are considered unequal to one another. Therefore, it is not possible to determine whether a value is not a number by using the equality operator to compare it to another value that is equal to NaN

其他提示

Unfortunately, when you test for inequality with double.NaN, it always returns true (the value itself is undefined). It's better to use double.IsNaN(rs1).

First, it can't be null because double is value type not reference type.So rs1 != null is redundant.Second you should use IsNaN method instead of check equality with ==

if(!double.IsNaN(rs1))
{
   ...
}

if(!Double.IsNaN(rs1)(float x = 0; x = (float)rs1;}

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top