XCode错误"二进制表达式的无效操作数"

时间:2012-06-26 07:33:04

标签: iphone ios5 xcode4.3

我有一个存储为double的NSTimeInterval。我想使用%运算符获得第二个值的分钟数。

int remainingSeconds = scratch % 60;

错误表示“二进制表达式的无效操作数”指向% 请帮助。

1 个答案:

答案 0 :(得分:21)

模数用于整数,因此要使代码工作,请执行以下操作

int remainingSeconds = (int)scratch % 60;

要在浮点数上使用模数,请使用fmod

int remainingSeconds = fmod(scratch, 60);

在这里查看答案How to make a modulo operation in objective-c / cocoa touch?

相关问题