October 14th, 2003, 09:38 AM
Not only that. The thing is that floor(-1.000001) is -2.0, so even if your FLT_MIN is only 0.0001 then it will fail.
Get this small utility
to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
October 14th, 2003, 10:29 AM
As said before, the string will not contain the '.' character. From what I understand, the captured number is kind of a monetary number, captured without the '.', but it still include 2 decimals (cents).
Originally posted by Kheun
Since you already captured the int/double value in the form of string, why not scan for the decimal point or '.'. If there exists non-zero value character(s) after the decimal point, the string presentation must be a double.
Checking the last 2 digits might be the more accurate solution, easy enough to implement.
A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
-- George Steiner
October 14th, 2003, 11:05 AM
Yves - depends on where/how you use fabs() !
double abs = fabs(dbl);
if ( ( abs - floor(abs) ) < FLT_MIN ) ...
(but you've made good point either way)
October 21st, 2003, 08:01 PM
Yeek. There has been some dodgy code posted here.
Firstly, you cannot use a simple floor() or modf() function. If you do, then 14.99999999999 will be rounded to 14, not 15.
On VC++ 6.0, FLT_MIN is 1.175494351e-38F, which is way too small for your epsilon value.
You might use FLT_EPS, which is 1.192092896e-07F, however you would be better looking at the data and deciding on a suitable epsilon value. You need to consider where the data came from, and how accurate it truely is. If it is only recorded to the nearest 0.1, then an epsilon value of 1.0e-7 is silly.
You might get something like this:
const double epsilon = 0.000001; // choose an appropriate value for this.
double Round(double val)
bool IsInt(double val)
return epsilon > fabs(val-Round(val));
Click Here to Expand Forum to Full Width