Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

ios - `isNan` in Objective-C

Is there a function like isNan (Javascript example) for Objective-C?

I just noticed this code is causing to display Nan %, so I need to detect is a value is NAN so I could change it to 0.

[portefeuillePercentWaarde setText:[NSString stringWithFormat:@"%.2f%%", verschilPrencentage]];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try just adding

#include <math.h>

and then using the standard isnan() function to test.

You can also use the "trick" that NaN is not equal to anything, including itself:

double x;

// do some operation here
x = doSomething();
if (x != x)
  printf("%g is probably NaN, it's not equal to itself
", x);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...