[英]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:参考:
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.