我正在开发一些代码,其中我使用扫描仪从字符串(例如 x 和 y)获取 NSNumbers。
现在我想根据 x 和 y 计算一些简单的值,例如 z = 10.0/(x + y/60.0)/60.0)。我无法直接执行此操作,因为编译器不喜欢应用于数字对象的普通算术符号系统。
因此,我尝试定义 double 类型的 xD 和 yD,然后尝试类型转换
xD = (double) x;
yD =(双)y;
但这也会产生编译错误。到底如何将 NSNumber 对象转换为在普通算术表达式中使用呢?我查阅了大量文献,但没有找到答案。
预先感谢您的任何帮助。
约翰·多纳
I an developing some code in which I use a scanner to get to NSNumbers from a string, say x and y.
Now I want to compute something simple from x and y, say, z = 10.0/(x + y/60.0)/60.0). I can't do this directly, since the compiler doesn't like ordinary arithmetic symbology applied to number objects.
So, I tried defining xD and yD, of type double, and then tried a type conversion
xD = (double) x;
yD = (double) y;
but that also gives a compile error. Just how does one get NSNumber objects converted to be used in ordinary arithmetic expressions? I did considerable browsing of the literature, and didn't find the answer.
Thanks in advance for any help.
John Doner
发布评论
评论(1)
使用 "value" 方法,例如
doubleValue
。Use the "value" methods of the NSNumber class such as
doubleValue
.