How can I check whether an initialized variable in c++ has integral value or floating point value?
The sample code block is shown below:
int main()
{
double number = 9.99;
if (/*Checks whether the value of the 'number' is an integral*/)
cout << "The 'number' has an integral value";
else
cout << "It's not an integral value" // This condition will true if 'number' has a floating point number
return 0;
}
number == static_cast<int>(number). However that have drawbacks like7.0being accepted as an integer. Also with the rounding problems of floating point values, a value could be very close to an integer, but not exactly.