0

I have reviewed same types of questions over stack overflow but this is different. Here i want to modulo double value with integer. And compiler is giving below error.

I need to get modulo value of scrollview content offset. For that i have written below code but it is giving me error 'Invalid operands to binary expression ('CGFloat' (aka 'double'))'. Any one please help.

scrollView.contentOffset.x % 1024.00;

Thanks in advance.

Nikh1414
  • 1,238
  • 2
  • 19
  • 35
  • the simpler solution is this: `(int) scrollView.contentOffset.x % (int)1024.00;`. From what i saw you cant use that operation on float/double – rob180 Dec 01 '15 at 15:17

2 Answers2

7

The Modulo operator % works only with integers.

You could cast the value(s) to int.

(int)scrollView.contentOffset.x % 1024;
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
vadian
  • 274,689
  • 30
  • 353
  • 361
3

You should use fmod(). Manpage.

CGFloat remainder = fmod(scrollView.contentOffset.x, 1024.00);
trojanfoe
  • 120,358
  • 21
  • 212
  • 242