【问题标题】:XCode error "invalid operands to binary expression"XCode 错误“二进制表达式的无效操作数”
【发布时间】:2012-06-26 07:33:03
【问题描述】:

我有一个存储为双精度的 NSTimeInterval。我想使用 % 运算符获取第二个值内的分钟数。

int remainingSeconds = scratch % 60;

错误表示“二进制表达式的无效操作数”指向 % 请帮忙。

【问题讨论】:

    标签: iphone ios5 xcode4.3


    【解决方案1】:

    模数用于整数,因此要让您的代码正常工作,请执行以下操作

    int remainingSeconds = (int)scratch % 60;
    

    要在浮点数上使用模数,请使用 fmod

    int remainingSeconds = fmod(scratch, 60);
    

    在这里查看答案How to make a modulo operation in objective-c / cocoa touch?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多