Piyo
Piyo

Reputation: 181

XCode error "invalid operands to binary expression"

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.

Upvotes: 8

Views: 12307

Answers (1)

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

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?

Upvotes: 21

Related Questions