CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. 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.

2. Originally posted by Kheun
avi123,

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.
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).

Checking the last 2 digits might be the more accurate solution, easy enough to implement.

3. Member
Join Date
Dec 2002
Posts
47
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)

-rick

4. Member
Join Date
Apr 2003
Location
Sydney, Australia
Posts
38
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:

Code:
```#include <cmath>

const double epsilon = 0.000001;  // choose an appropriate value for this.

double Round(double val)
{
return floor(val+0.5);
}

bool IsInt(double val)
{
return epsilon > fabs(val-Round(val));
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•