Objective-C中的`isNan` [英] `isNan` in Objective-C

查看:122
本文介绍了Objective-C中的`isNan`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Objective-C有一个类似的函数isNan (Javascript示例)吗?我刚刚注意到这段代码导致显示 Nan%,所以我需要检测一个值是Nan,所以我可以将它改为0.。

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]];


推荐答案

尝试添加

#include <math.h>

然后使用标准 isnan()功能测试。

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

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

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);

这篇关于Objective-C中的`isNan`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆