Most Efficient Way to Check a Variable Is A Whole Number
Hi,
I have a question. Say you have a variable of type double, and you want to check if it is a whole number or not. What is the most efficient way to do this? At present I am doing something like this, but it doesn't seem very efficient.
Code:
#include <iostream>
using namespace std;
int main()
{
double a_dbl = 3.5;
int a_int = static_cast<int>(a_dbl);
if (a_dbl == a_int)
cout << "a_dbl is a whole number";
else
cout << "a_dbl is not a whole number";
}
Thanks guys.