简体   繁体   English

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

[英]XCode error “invalid operands to binary expression”

I have an NSTimeInterval that is stored as a double. 我有一个NSTimeInterval存储为double。 I would like to get the amount of minutes that are inide of the second value using the % operator. 我想使用%运算符获得第二个值的分钟数。

int remainingSeconds = scratch % 60;

The error said "invalid operands to binary expression" point at % Help please. 错误表示“二进制表达式的无效操作数”指向%Help请。

modulus is used on integers, so for your code to work do the following 模数用于整数,因此要使代码工作,请执行以下操作

int remainingSeconds = (int)scratch % 60;

To use modulus on floats use fmod 要在浮点数上使用模数,请使用fmod

int remainingSeconds = fmod(scratch, 60);

check answer here How to make a modulo operation in objective-c / cocoa touch? 在这里查看答案如何在objective-c / cocoa touch中进行模运算?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM