Ducnan:
Usually whenever you compare two different doubles/floats, you should use a
tolercance value (according your problem-set needs). That is, if both
doubles are within some tolerance of each other, for this problem, say 0.001
or 0.0001, then they are considered equivalent. This helps eliminate the
problems with rounding like you are seeing when you convert using atof().
So here would be a function to do this......
if (double_equiv(0.58, atof(arg), 0.001)) {
//THEY ARE EQUAL
}
bool double_equiv(double val1, double val2, double tolerance)
{
bool equiv=false;
if (fabs(val1 - val2)<=tolerance) {
equiv = true;
}
return equiv;
}
...Hope this helps....
-TGF
"Duncan Winn" <te**@test1.co.uk> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
I am trying to convert a CString to a double using
atof()
however my nice CString of "0.58" gets converted to 0.579999223213147 etc
making it impossible to compare with a different double varaible of 0.58
Any suggestions on how to keep my origional value!!!!
Thanks
Ducnan