Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C++
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;
  }

}
Posted

1 solution

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:
C++
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:
C++
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900