gpt4 book ai didi

c# - 我如何过滤掉 NaN 值并将其替换为另一个值

转载 作者:行者123 更新时间:2023-11-30 14:31:06 26 4
gpt4 key购买 nike

iv'尝试使用 for 循环过滤掉 null 和 nan 值,但 nan 值仍被添加到 ListView 中。这只是完成计算的部分。

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");
}

最佳答案

使用IsNan static function,了解它here

你的代码应该是这样的

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

带有 NaN 的 NaN 将始终返回 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

关于c# - 我如何过滤掉 NaN 值并将其替换为另一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21214112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com