Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:46:18+00:00 2026-06-14T23:46:18+00:00

I have 2 nullable doubles, an expected value and an actual value (let’s call

  • 0

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). However, if valueExpected is zero, it returns NaN. Everything good so far.

Now, what do I do if I need to check the value, to see if it is NaN? Normally one could use:

if (!Double.IsNaN(myDouble))

But this doesn’t work with nullable values (IsNaN only works with non-nullable variables). I have changed my code to do the check (valueExpected == 0), but I’m still curious – is there any way to check for a nullable NaN?

Edit: When I say the code doesn’t work, I mean it won’t compile. Testing for null first doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:46:20+00:00Added an answer on June 14, 2026 at 11:46 pm

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

    double? d = 0.0;        // Shorthand for Nullable<double>
    if (d.HasValue && !Double.IsNaN(d.Value)) {
        double val = d.Value;
    
        // val is a non-null, non-NaN double.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following exception: Nullable object must have a value Everything was
How can I convert TO a Nullable from a String using reflection? I have
I'm using SQL Server and in one of the tables I have a nullable
I have a nullable bool. What is a quick way to invert it. In
If I have a nullable decimal? d and I want to assign d to
I have a list of nullable integer and it look like a 1 to
I have a Person object with a Nullable DateOfBirth property. Is there a way
So I have the following snippet of code: private Nullable<decimal> _excessWages; public decimal ExcessWages
Dynamic Data question: I have 2 fields of type Nullable<DateTime> on my model When
I'm working with .NET strongly-typed datasets and have a table with a nullable int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.