Nullable double NaN comparison in C#

后端 未结 4 1797
独厮守ぢ
独厮守ぢ 2021-01-12 18:03

I have 2 nullable doubles, an expected value and an actual value (let\'s call them value and valueExpected). A percentage is found using 100 * (value / valueExpected). Howev

4条回答
  •  梦谈多话
    2021-01-12 18:51

    With all Nullable instances, you first check the bool HasValue property, and then you can access the T Value property.

    double? d = 0.0;        // Shorthand for Nullable
    if (d.HasValue && !Double.IsNaN(d.Value)) {
        double val = d.Value;
    
        // val is a non-null, non-NaN double.
    }
    

提交回复
热议问题