开发者

`isNan` in Objective-C

开发者 https://www.devze.com 2022-12-17 10:59 出处:网络
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.

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 setT开发者_StackOverflowext:[NSString stringWithFormat:@"%.2f%%", verschilPrencentage]];


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\n", x);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号