简体   繁体   English

'double' 和 'int' 类型的无效操作数到二进制 'operator%'

[英]invalid operands of types 'double' and 'int' to binary 'operator%'

There !那里 !

In one of the my project i am trying to print Float value on seven segment display using Arduino Mega2560 with given codes, But i am getting correct data with decimal values but now when i am trying to print float values unfortunately getting the error as mentioned on title.在我的一个项目中,我正在尝试使用 Arduino Mega2560 和给定代码在七段显示器上打印浮点值,但是我正在使用十进制值获得正确的数据,但是现在当我尝试打印浮点值时,不幸的是得到了上面提到的错误标题。

Float value's code which i am trying to compile我正在尝试编译的浮点值代码

switch (current_digit)
{
case 1:
 disp(fmodf (adc_value, 10000000));   //8   
 digitalWrite(digit_7, HIGH);  
 break;
 
case 2:
 disp(fmodf (adc_value, 1000000)% 10);   //7
 digitalWrite(digit_6, HIGH);  
 break;
 
case 3:
 disp(fmodf (adc_value, 100000)% 10);   //6
 digitalWrite(digit_5, HIGH);  
 break;
 
case 4:
 disp(fmodf (adc_value, 10000)% 10);   //5
 digitalWrite(digit_4, HIGH);  
 break;
  
case 5:
  disp(fmodf (adc_value, 1000)% 10); //4  
  digitalWrite(digit_3, HIGH); 
   digitalWrite(SegGDP,LOW); 
  break;

case 6:
  disp( fmodf (adc_value, 100) % 10);  //3 
  digitalWrite(digit_2, HIGH);        
  break;

case 7:
  disp( fmodf (adc_value, 10) % 10);   //2
  digitalWrite(digit_1, HIGH);   
  break;

case 8:
  disp(fmodf (adc_value, 10));   //1
  digitalWrite(digit_0, HIGH);  
}

References:参考:

  1. Float value references 浮点值引用

  2. Invalid operands of type 'double' and 'int' to binary 'operator%' 'double' 和 'int' 类型的无效操作数到二进制 'operator%'

fmodf returns a float. fmodf返回一个浮点数。 So所以

fmodf(adc_value, 1000000)% 10

will still attempt float % int .仍将尝试float % int

However, that code does probably not what you want it to do.但是,该代码可能不是您想要的。 The equivalent of相当于

(adc_value / 1000000) % 10

should be应该

fmodf(adc_value / 1000000.f, 10.f)
case 1:
 disp(fmodf (adc_value, 10000000));   //8   

You want floor(adc_value / 10000000) instead, which would be the float equivalent of the integer division adc_value / 10000000 .您想要floor(adc_value / 10000000)代替,这将是 integer 除法adc_value / 10000000的浮点等价物。

case 2:
 disp(fmodf (adc_value, 1000000)% 10);   //7

There is no % between a floating point value and an integer, so here is where you want fmodf as in fmodf ( floor(adc_value / 1000000), 10) .浮点值和 integer 之间没有% ,所以这里是你想要fmodf的地方,就像fmodf ( floor(adc_value / 1000000), 10)

暂无
暂无

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

相关问题 二进制“ operator%”的类型为“ double”和“ int”的无效操作数 - invalid operands of types `double' and `int' to binary `operator%' int类型的无效操作数和二进制&#39;operator%&#39;的double - invalid operands of types int and double to binary 'operator%' 'int' 和 'int [3]' 类型的无效操作数到二进制 'operator*' - invalid operands of types ‘int’ and ‘int [3]’ to binary ‘operator*’ 二进制“ operator%”的类型为“ double”和“ int”的无效操作数 - Invalid operands of type 'double' and 'int' to binary 'operator%' 类型为&#39;double *&#39;和&#39;double&#39;的无效操作数到二进制&#39;operator +&#39; - invalid operands of types 'double*' and 'double' to binary 'operator+' 错误:“double”和“double”类型的无效操作数转换为二进制“operator%” - error: invalid operands of types ‘double’ and ‘double’ to binary ‘operator% 类型为“ double”的无效操作数snd const char [3]”转换为二进制“ operator &lt;&lt;” - invalid operands of types ‘double’ snd const char [3]’ to binary 'operator<<' 二进制“ operator!=” |的类型为&#39;double&#39;和&#39;const char [2]&#39;的无效操作数 - Invalid operands of types 'double' and 'const char [2]' to binary 'operator!='| 错误:C ++中类型为“ float”和“ int”的二进制“ operator%”类型的无效操作数 - error: invalid operands of types 'float' and 'int' to binary 'operator%' in c++ 错误:类型为&#39;const char [3]&#39;和&#39;int *&#39;的无效操作数为二进制&#39;operator *&#39; - Error: invalid operands of types 'const char [3]' and 'int*' to binary 'operator*'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM