在iOS应用中使用mod运算符

Jer*_*rry 8 iphone nstimeinterval modulus

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

minutes = secondValue % 60;
Run Code Online (Sandbox Code Playgroud)

将分钟声明为 double minutes

结果是XCode说"二进制%的操作数无效"

思考?

Car*_*rum 13

从C标准,6.5.5乘法运算符,第2节:

运算%符的操作数应为整数类型.


Alc*_*ive 12

The OP changed their question, so here is my new answer:

你想要做minutes = floor(secondsValue) / 60; 你想要int除法,而不是模数.