我想写代码(0W~4000000.000W)但我的数据过滤器没有用。 [英] I want to write code like (0W ~4000000.000W) but my data filter no work.
本文介绍了我想写代码(0W~4000000.000W)但我的数据过滤器没有用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据类型是这样的。
单位:1mW |数据范围0W~4,000,000.000W Int32
当数据不符合声明时,我会发现错误信息。
double RountEx( double value _, int pos)
{
double b = _Pow_int( 10 跨度>,POS);
double temp = value _ * _ Pow_int( 10 ,pos);
temp = floor(temp- 0 。 5 );
temp / = _ Pow_int( 10 ,pos);
return temp;
}
// 编辑控件
void CheckData()
{
Edit_DischargePowerLimit.GetWindowTextA(strPowerData);
double PowerData = _tstof(strPowerData);
// if 3999999.999
double 结果= RountEx(PowerData, 3 );
if ((PowerData< = 0 )&&(PowerData< ; = - 4000000 。 000 ))
{
int IData = int (PowerData);
}
else if ((PowerData< 0)&&( PowerData> = - 4000000 .000 + 0。 001 ))
{
AfxMessageBox( Over Range\\\
!);
return ;
}
}
解决方案
从你的代码中可以看出你所接受的范围是否是( 0 - 4000000)或(-4000000 - 0),但既然你在谈论瓦特我就假设前者。在这种情况下,你的比较有一个逻辑缺陷:
if ((PowerData< = 0 )&&(PowerData< = - 4000000 。 000 ))
检查该值是否小于零且小于四百万。您可能希望接受范围从零到四百万的值,包括:
if ((PowerData > = 0 )&&(PowerData< = 4000000 。 000 ))
{
int IData = int 跨度>(PowerData);
}
else
{
AfxMessageBox( Over Range \\\
!);
return ;
}
你不需要对其他条件有条件,因为你已经知道价值已经超出范围。
I made data type like this.
Unit : 1mW | Data Range 0W~ 4,000,000.000W Int32
I'll notice error message when data doesn't fit statement.
double RountEx(double value_,int pos)
{
double b= _Pow_int(10,pos);
double temp= value_*_Pow_int(10,pos);
temp=floor(temp-0.5);
temp/=_Pow_int(10,pos);
return temp;
}
//Edit control
void CheckData()
{
Edit_DischargePowerLimit.GetWindowTextA(strPowerData);
double PowerData = _tstof(strPowerData);
//if 3999999.999
double Result=RountEx(PowerData,3);
if((PowerData<= 0)&& (PowerData<=-4000000.000))
{
int IData= int(PowerData);
}
else if((PowerData<0) && (PowerData >= -4000000.000+0.001))
{
AfxMessageBox("Over Range\n!");
return;
}
}
解决方案
It's not clear from your code if your accepted range is (0 - 4000000) or (-4000000 - 0), but since you are talking about Watts I assume the former. In that case, your comparisons have a logic flaw:
if((PowerData<= 0)&& (PowerData<=-4000000.000))
checks if the value is both less than zero and less than minus four million. You probably want to accept values that range from zero to four million, inclusive:
if ((PowerData >= 0) && (PowerData <= 4000000.000)) { int IData= int(PowerData); } else { AfxMessageBox("Over Range\n!"); return; }
You don't need to have a condition on the else, since you already know the value is out of range.
这篇关于我想写代码(0W~4000000.000W)但我的数据过滤器没有用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文