XCode error "invalid operands to binary expression"

Piyo picture Piyo · Jun 26, 2012 · Viewed 11.9k times · Source

I have an NSTimeInterval that is stored as a 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.

Answer

Omar Abdelhafith picture Omar Abdelhafith · Jun 26, 2012

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

int remainingSeconds = fmod(scratch, 60);

check answer here How to make a modulo operation in objective-c / cocoa touch?