Objective-C中的`isNan`

Joh*_*ast 4 iphone

有一个像isNanObjective-C 的函数(Javascript示例)?我只是注意到这个代码导致显示Nan %,所以我需要检测是一个值是楠所以我可以将其更改为0.

[portefeuillePercentWaarde setText:[NSString stringWithFormat:@"%.2f%%", verschilPrencentage]];
Run Code Online (Sandbox Code Playgroud)

unw*_*ind 22

尝试添加

#include <math.h>
Run Code Online (Sandbox Code Playgroud)

然后使用标准isnan()函数进行测试.

你也可以使用NaN不等于任何东西的"技巧",包括它自己:

double x;

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